在SQLServer中显示表结构的脚本片

在SQLServer中显示表结构的脚本片,第1张

在SQLServer中显示表结构的脚本片,第2张

用于在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

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 在SQLServer中显示表结构的脚本片

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情