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 2000 Forums
 SQL Server Development (2000)
 Defaults in SQL Server Tables

Author  Topic 

goblyn27
Starting Member

39 Posts

Posted - 2002-03-15 : 21:09:06
Im trying to find out how to tell through an SQL query against the syscolumns object what the default value for a column (if any) is and Im not having much luck so I thought I should post the question here.

Any help is appreciated
thank you

"DuuuDe!! I suck!"

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-03-15 : 22:11:02
This should give you a start. Basically the syscolumns table attaches to the syscomments table, which houses the default values.

SELECT c.name Table_Name, a.name Column_Name, b.text Default_Value
FROM dbo.syscolumns a, dbo.syscomments b, dbo.sysobjects c
WHERE a.cdefault = b.id
and a.id = c.id

Jeremy


Go to Top of Page
   

- Advertisement -