Tags


Get Table Schema in SQL Server

Following procedure Generate the table schema with column name type and size

Create procedure GetTableSchema
@TableName varchar(250)
as
Begin
select substring(o.name,1,50) as ‘Table Name’,
c.colid,
substring(c.name,1,30) as ‘Column Name’,
substring(t.name,1,30) as ‘DataType’,
c.length
from sysobjects o (NOLOCK)
left join syscolumns c on (o.id=c.id)
left join systypes t on (c.xusertype=t.xusertype)
where
substring(o.name,1,250) like ‘%’+@TableName+’%’
and
o.type=’U’
order by 1 ASC
end

Enjoy!!

Advertisements