Showing posts with label default. Show all posts
Showing posts with label default. Show all posts

Monday, March 26, 2012

Query which system table to answer this

I have a DB with 1 default defined: UW_Zerodefault
It simply puts a 0 into particular fields upon new record creation.
Is there a query I can run against a particular system table to give me a list of fields this default is applied against in the DB?
ThanksSqlSpec will give you this information, but I can't remember now what table it's hitting to get it. it may be as simple as querying sysdepends.

I'll take a look at the code tonight and post again.|||If I understand your query correctly (It's late and I'm tired!!) you can run exec sp_mshelpcolumns 'enter table name' and the col_dridefname column is the contraint name and the first text column is the default value.|||this give you all default usage by columns:

select
s.name as colname
,o1.name as tablename
,o2.name as defaultname
from
syscolumns s
inner join
sysobjects o1 on o1.id=s.id
inner join
sysobjects o2 on o2.id=s.cdefault

and this will give you default usage by udts:

exec sp_mshelptype @.typename=null, @.flags='uddt'

Friday, March 9, 2012

Query to find default value for a column

Where are the default values for a column stored in SQL Server. I thought
they would be in the syscolumns table, but I cannot find them there, nor
anywhere else for that matter.
Thanks,
Jasonget the cdefault from syscolumns and
select from syscomments for the id
syscomments.id = syscolumns.cdefault.
Let me know if this helps
"JasonDWilson" wrote:

> Where are the default values for a column stored in SQL Server. I thought
> they would be in the syscolumns table, but I cannot find them there, nor
> anywhere else for that matter.
> Thanks,
> --
> Jason|||Try this:
select distinct substring(object_name(c.id), 1, 50) 'Table Name'
, substring(c.name, 1, 40) 'Column Name'
, object_name(c.cdefault)'Default Name'
from syscolumns c,
syscomments m
where m.id = c.cdefault
Perayu
"JasonDWilson" <JasonDWilson@.discussions.microsoft.com> wrote in message
news:E45274CE-E559-40E0-805E-7DD5037D90BD@.microsoft.com...
> Where are the default values for a column stored in SQL Server. I thought
> they would be in the syscolumns table, but I cannot find them there, nor
> anywhere else for that matter.
> Thanks,
> --
> Jason