您的位置:首页 > 数据库

数据库_基础代码<sql>

2012-08-08 17:19 519 查看
以table1 <含字段:id,name> 为例:



--是否存在

if exists(select 1 from sysobjects where id = object_id('table1'))

--修改表名

alter table1 rename to table2

--添加列

alter table table1 add Status int default 1

--添加列的约束

ALTER TABLE tablename ADD CONSTRAINT DF_tablename_列名 DEFAULT(0) FOR 列名

--修改列

alter table table1 alter column name varchar(50)

--修改列名

alter table table1 column name to name1

--删除列

alert table table1 drop column name

--删除关系

alert table table1 drop constraint GuanXiMing

存储过程

---是否存在

if exists(select 1 from sysobjects where id=object_id(proc1) and xtype='p')

drop procedure proc1

--创建

create procedure proc1

as

decare....

触发器

if exists(select * from dbo.sysobjects where id =object_id('trig1)and objectProperty(id,N'IsTrigger')=1)

drop trigger trig1

--创建

Create Trigger UpdateTrigger_table1

on T_CorrespondentNode

for UPDATE

as

....
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐