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 表名称
(
列名称
)
--
复制表及数据(从
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语句
- 学生登录SQL语句,包括check约束,唯一索引,主键
- 创建数据库、表、主外键、各种约束、存储过程、视图、索引、事务使用、触发器、创建登录账号、数据库用户 Sql语句示例
- SQL语句新建表,同时添加主键、索引、约束
- SQL基础语句(数据库函数,时间函数,Union,Case,索引)
- 常用sql语句-高级特性(事务,索引,约束)
- oracle导出创建用户下各个对象数据结构的sql语句的脚本,包括表、视图、索引、约束等等
- 【搬家】【数据库】【优化】SQL 优化学习小结——索引和语句优化
- SQL语句调优-基础知识准备
- mysql优化(SQL语句的优化以及索引的应用范围)
- 使用SQL语句为SQL Server 2005创建全文索引
- SQL基础--> 约束(CONSTRAINT)
- oralce 基础知识 ,oralce 常用简单sql语句,oracle 新手必看之一
- QL之-建库、建表、建约束、关系SQL基本语句
- 常用SQL语句汇总——基础
- Oracle基础 动态SQL语句
- sql语句的where条件顺序和索引的顺序
- SQL 关于表约束的相关执行语句
- SQL基础语句
- SQL基础--> 约束(CONSTRAINT)