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
 Transact-SQL (2000)
 Value of the default from system tables

Author  Topic 

Mike@Work
Starting Member

4 Posts

Posted - 2002-09-26 : 17:16:33
I need to compare 2 schemas and I was wondering how I can pull the value of a default from some system table. I know I can get the name from sysobjects but I haven't found how to pull the value from sysobjects.

TIA!

Mike

Mike@Work
Starting Member

4 Posts

Posted - 2002-09-26 : 17:17:49
Hmmmm, sorry for the double post. I only hit Post once. :(
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-26 : 17:54:30
Actually, it's even easier to use the INFORMATION_SCHEMA.COLUMNS view:

SELECT TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='myTable'
--change the table name or completely remove the WHERE clause if you want all tables

There are more columns available in INFORMATION_SCHEMA.COLUMNS, like data type, size, etc. See Books Online for more information.

The INFORMATION_SCHEMA views should be used instead of querying system tables, basically because they follow ANSI standards and also because system tables change structure from one version of SQL Server to the next.

Go to Top of Page

Mike@Work
Starting Member

4 Posts

Posted - 2002-09-27 : 09:29:25
Hey that's cool. I don't remember seeing those before, they're new to 2K?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-27 : 09:41:15
They were introduced in SQL 7.0, and I think SQL 2000 added some new ones, but COLUMNS was always available.

Go to Top of Page
   

- Advertisement -