表专区
-- 复制表及数据(从 userinfo 表复制到新表 b
select * into b from UserInfo
-- 获取当前数据库中的所有用户表
select * from sysobjects where xtype='U' and category=0
-- 获取某一个表的所有字段
select name from syscolumns where id=object_id('表名')
约束专区
-- 查询表 约束
exec sp_helpconstraint 表名
-- 添加外键约束
alter table 表名 add constraint 外键名 foreign key ( 引用列名 ) references 被引用表名 ( 列名 )
索引专区
----查找表中的索引
select * from sysindexes where id = object_id ( ' 表名 ' )
exec sp_helpindex g_Account
----- 判断是否存在索引
select * from sysindexes where name = '索引名 '
--创建索引
CREATE UNIQUE INDEX 索引名称 ON 表名称 ( 列名称 )