--声明游标,admin是一个表的名称,该游标标识了该表中的属性名称
DECLARE Column_Name CURSOR FOR SELECT name FROM sys.columns WHERE object_id = object_id('admin');
--打开游标
OPEN Column_Name;
DECLARE @Column_Name VARCHAR(100)
--从游标中获取数据,
FETCH Column_Name INTO @Column_Name
--WHILE循环,遍历游标,当@@FETCH_STATUS为0时,表示游标遍历完毕
WHILE(@@FETCH_STATUS = 0)
BEGIN
--打印记录
PRINT(@Column_name)
--获取下一条记录
FETCH NEXT FROM Column_Name INTO @Column_Name;
END
--关闭游标
CLOSE Column_Name
--删除游标
DEALLOCATE Column_Name