您的位置:首页 > 数据库

SQL 基础语句【表、约束、索引】

2010-04-14 20:26 253 查看
表专区

--
复制表及数据(从
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 表名称 
(
列名称


 
 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql object 数据库