I execute a select to get the structure of a table. I want to get info about the columns like its name or if it's null or if it's primary key.. I do something like this
....sys.columns c...
c.precision,
c.scale,
c.is_nullable as isnullable,
c.default_object_id as columndefault,
c.is_computed as iscomputed,
but for default value i get the id..something like 454545454 but i want to get the value "xxxx". What is the table to search or what is the function to convert that id to the value. Thanks
5条答案
按热度按时间oprakyz71#
You can do this (done a SELECT * just so you can see all the info available):
This includes a "COLUMN_DEFAULT" column in the resultset.
zpgglvta2#
Use
there is a column called
COLUMN_DEFAULT
hi3rlvi23#
The property you want is called "cdefault".
http://sql-server-performance.com/Community/forums/p/20588/114944.aspx
kupeojn64#
'bills' is an example table
krcsximq5#
If you want to focus on the DEFAULT values, the built-in function GETDEFAULT can help, but as long as it requires to use numbers (you can't use a DB_ID(), a column or even a variable with the function) to escape this I made a procedure:
This procedure only needs the table name and returns all the columns from the table that have default values and the active default values, example: