在SQLServer中显示表结构的脚本片
用于在SQL Server中显示表结构的脚本片段:
例如,如果object _ id ('dbo.sp _ show table ')不为NULL
begin
drop procedure dbo . sp _ show table
如果OBJECT_ID('dbo.sp_showtable ')不为NULL
PRINT ' '
ELSE
PRINT ' '
END
go
SET ANSI _ SET
创建过程[dbo]。[sp _ show table]@ tablename varchar(50)
as
begin
select ' * * * * * * * * * * * * * * * * * * * * * * * * * * * '
print @ tablename+' Structure is '
select b . name as column name,case when c . name in
(' nvarchar ',' char ',' nchar ',' varchar ')then c . name+'
('+convert(varchar(4),b.prec)????????'
end as Type,
case b . is nullable when 0 then ' not
Null ' else ' Null ' end as ' Null '
from sys objects a,syscolumns b,systypes c
其中a.name=@tablename
和a.id=b.id
和b.usertype=c.usertype
和b . xusertype = c . xusertype
order by b . color
目标
go
SET ANSI _ NULLS OFF
go
SET QUOTED _ IDENTIFIER OFF
go
如果OBJECT_ID('dbo.sp_showtable ')不为NULL
PRINT ' '
ELSE
PRINT ' '
go
如果OBJECT _ ID(' dbo . sp _ showtable _ insert ')不为NULL
BEGIN
DROP PROCEDURE dbo . sp _ showtable _ insert
如果OBJECT _ ID(' dbo . sp _ showtable _ insert ')不为NULL
PRINT ' '
ELSE
PRINT ' '
END
go
SET ANSI _ NULLS ON
go
SET QUOTED _ IDENTIFIER ON
0条评论