Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get the default value for a field?

Author  Topic 

drh3010
Starting Member

18 Posts

Posted - 2007-12-17 : 15:44:45
Anyone know how to get the default value for a field? Apparently ODBC can't do it, so I need to resort to a raw SQL statement.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-17 : 15:48:49
select column_default
from information_schema.columns
where table_name = 'sometable' and column_name = 'somecolumn'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-17 : 15:51:37
[code]select column_default
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'table1'
and COLUMN_NAME = 'col1'[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-17 : 15:52:18




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -