Search code examples
sqlimagestore

Is it ok to store all types of values as image data type in sql?


Is it ok to store data of different data types as a single universal data type, say 'image' in SQL? I will also store the data type value in another column and use this value inside my code to convert the data back into its proper type. The advantage I get by doing this - I can avoid joining n number of tables. Can some one point me to the down sides of storing data in this way?


Solution

  • This is a pretty bad idea for several reasons:

    • Query performance will be bad because the optimizer can't utilize indexes, foreign keys etc. because they don't exist.
    • You don't get referential integrity and thus can make no assumption about your data.
    • You introduce a new additional point of failure, because what if the data doesn't correspond to the specified data type?
    • The person having to maintain the code after you will hate you.