Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql server : get default value of a column

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

like image 541
luke Avatar asked Apr 07 '10 08:04

luke


2 Answers

You can do this (done a SELECT * just so you can see all the info available):

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE....

This includes a "COLUMN_DEFAULT" column in the resultset.

like image 149
AdaTheDev Avatar answered Oct 06 '22 04:10

AdaTheDev


Use

Select * From INFORMATION_SCHEMA.COLUMNS

there is a column called COLUMN_DEFAULT

like image 28
codingbadger Avatar answered Oct 06 '22 04:10

codingbadger