Author |
Topic |
michaels-r
Starting Member
4 Posts |
Posted - 2008-07-16 : 15:12:27
|
Hi - I am having total brain fade tonight and cannot remember how to make multiple cols of different types share the same data space. e.g. you have val_type which specifies the type of value being stored and can access the data using val_int or val_char etc. where val_int and val_char occupy the same space in the table.Thanks,Michael |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
michaels-r
Starting Member
4 Posts |
Posted - 2008-07-16 : 16:04:52
|
If I could give you an example it would not be a problem! However, I will try to explain again:You have a table with a column defining a data type of either: 'Integer' or 'Char'A further column contains the data: ValueHowever, rather than putting a value into the column Value, I want to have 2 fields: Value_i and Value_c pointing to the same physical location (2 aliases for the Value column with different data types)... have I just answered my own question or is there another way, similar to the C/C++ union?Thanks, Michael |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
michaels-r
Starting Member
4 Posts |
Posted - 2008-07-16 : 17:18:49
|
No, not a computed column, a native one.A union in C++ is a structure where there are 2 or more names for the same variable, all of which have different types but occupy the same memory space. Generally you will set the value and access it using the same name at a given time. It's essentially a mechanism to allow indirection - which is what I am trying to achieve here but may be completely off the mark.Simplifying the problem, what I am trying to do is create a table with 2 columns:CREATE TABLE T1( ValueI Int, ValueD Decimal);But have ValueI and ValueD actually be the same column, sharing the same storage space. The idea being that another reference table will dictate what the actual type is i.e which name to use to access the data.Thanks, Michael |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
michaels-r
Starting Member
4 Posts |
Posted - 2008-07-16 : 20:10:21
|
OK - thanks. I did start to wonder if my memory was failing me.... :-) |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-07-16 : 21:49:30
|
That would be achieveable using computed column, but in the context of a db design forum I have to ask why.Is this some dodgy attempt at 'typifying' as EAV by any chance? |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-07-16 : 23:23:18
|
>> have ValueI and ValueD actually be the same column, sharing the same storage space.Do you mean sql_variant type? |
|
|
|