I’m trying to figure out a way to store metadata about a column without repeating myself.
I’m currently working on a generic dimension loading SSIS package that will handle all my dimensions. It currently does :
- Create a temporary table identical to the given table name in parameters (this is a generic stored procedure that receive the table name as parameter, and then do :
select top 0 * into ##[INSERT ORIGINAL TABLE NAME HERE] from [INSERT ORIGINAL TABLE NAME HERE]). - ==> Here we insert custom code for this particular dimension that will first query the data from a datasource and get my delta, then transform the data and finally loads it into my temporary table.
- Merge the temporary table into my original table with a T-SQL MERGE, taking care of type1 and type2 fields accordingly.
My problem right now is that I have to maintain a table with all the fields in it to store a metadata to tell my scripts if this particular field is type1 or type2… this is nonsense, I can get the same data (minus type1/type2) from sys.columns/sys.types.
I was ultimately thinking about renaming my fields to include their type in it, such as :
FirstName_T2, LastName_T2, Sex_T1 (well, I know this can be type2, let’s not fall into that debate here).
What do you guyz would do with that? My solution (using a table with that metadata) is currently in place and working, but it’s obvious that repeating myself from the systables to a custom table is nonsense, just for a simple type1/type2 info.
UPDATE: I also thought about creating user defined types like varchar => t1_varchar, t2_varchar, etc. This sounds like something a bit sluggy too…
I know this is bad, but I will post an answer to my own question… Thanks to GBN for the help tho!
I am now storing “flags” in the “description” field of my columns. I, for example, can store a flag this way : “TYPE_2_DATA”.
Then, I use this query to get the flag back for each and every column :
Now I can store metadata about columns without having to create a separate table. I use what’s already in place and I don’t repeat myself. I’m not sure this is the best possible solution yet, but it works and is far better than duplicating information.
In the future, I will be able to use this field to store more metadata, where as : “TYPE_2_DATA|ANOTHER_FLAG|ETC|OH BOY!”.
UPDATE :
I now store the information in separate extended properties. You can manage extended properties using
sp_addextendedpropertyandsp_updateextendedpropertystored procedures. I have created a simple store procedure that help me to update those values regardless if they currently exist or not :Thanks again