时间:2021-05-02
复制代码 代码如下:
create proc p_sword_getblcolumn
(
@tblName varchar(200),
@fromIndex int,
@toIndex int,
@columnName varchar(3000) output
)
as
begin
declare @tempColumn varchar(3000)
declare @errMsg varchar(200)
declare @i int
set @i=1
set @columnName=''
set @errMsg=''
declare tempColumnCur cursor for
select syscolumns.name from syscolumns join sysobjects on syscolumns.id = sysobjects.id
where sysobjects.name =@tblName order by syscolumns.colorder
open tempColumnCur
fetch next from tempColumnCur into @tempColumn
while @@FETCH_STATUS=0
begin
if(@fromIndex=0 and @toIndex=0)
begin
set @columnName=@columnName+','+@tempColumn
end
if(@fromIndex=0 and @toIndex<>0)
begin
if(@i<=@toIndex)
set @columnName=@columnName+','+@tempColumn
end
else if(@fromIndex <>0 and @toIndex=0)
begin
if(@i>=@fromIndex)
set @columnName=@columnName+','+@tempColumn
end
else if(@i>=@fromIndex and @i<=@toIndex)
begin
set @columnName=@columnName+','+@tempColumn
end
set @i=@i+1
print @i
fetch next from tempColumnCur into @tempColumn
end
close tempColumnCur
deallocate tempColumnCur
set @columnName=SUBSTRING(@columnName,2,len(@columnName))
print @columnName
if(@@ERROR<>0)
begin
set @errMsg='get column error '
goto errorproc
end
else
return 0
end
errorproc:
begin
raiserror(@errMsg,16,1)
return 1
end
go
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
☆获取数据库所有表名,表的所有列名selectnamefromsysobjectswherextype='u'selectnamefromsyscolumnsw
alerttable表名addcolumn列名altertable表名dropcolumn列名eg:altertableTPointManageaddAddPo
语法:CREATE[索引类型]INDEX索引名称ON表名(列名)WITHFILLFACTOR=填充因子值0~100GOUSE库名GOIFEXIS
创建存储过程表名和比较字段可以做参数的存储过程CreatePROCEDUREsp_getTeacherInfo@TblNamenvarchar(30),--表名
需求如下导出表的结构,和字段备注信息,表名等。不需要借用第三方工具即可实现。SELECTTABLE_NAME表名,COLUMN_NAME列名,COLUMN_TY