Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Column names and properties


Message #1 by "Nanda Kumar" <nandu@n...> on Tue, 27 Feb 2001 08:50:43 +0530
> THanks for your responses, I am trying to get these details 
> from SQL server
> 7.0. I could get them through the in-built stored procedures, 
> but can we
> write any sql to retrieve these values?
> 

try this:

declare @no varchar(35), @yes varchar(35), @none varchar(35)
select @no = name from master.dbo.spt_values where type = 'B' and number = 0
select @yes = name from master.dbo.spt_values where type = 'B' and number 
1
select @none = name from master.dbo.spt_values where type = 'B' and number 
2
declare @numtypes nvarchar(80)
select @numtypes 
N'tinyint,smallint,decimal,int,real,money,float,numeric,smallmoney'

select so.name [Table Name],


'Column_name' = sc.name,
'Type' = type_name(xusertype),
'Computed' = case when iscomputed = 0 then @no else @yes end,
'Length' = convert(int, length),
'Prec' = case when charindex(type_name(sc.xtype), @numtypes) > 0
		then convert(char(5),ColumnProperty(sc.id, sc.name,
'precision'))
		else '     ' end,
'Scale'	= case when charindex(type_name(sc.xtype), @numtypes) > 0
		then convert(char(5),OdbcScale(sc.xtype,xscale))
		else '     ' end,
'Nullable' = case when isnullable = 0 then @no else @yes end,
'TrimTrailingBlanks' = case ColumnProperty(so.id, sc.name, 'UsesAnsiTrim')
			when 1 then @no
			when 0 then @yes
			else '(n/a)' end,
'FixedLenNullInSource'	= case when type_name(sc.xtype) not in
('varbinary','varchar','binary','char') Then '(n/a)'
				When sc.status & 0x20 = 0 Then @no
				Else @yes END
from sysobjects so
inner join syscolumns sc on so.id=sc.id
where so.xtype='U'

  Return to Index