SQL 2005(二)

检查数据库是否存在:
if db_id('数据库名')is not null--ASCII码,一个字符占一个字节,if db_id('N数据库名')is not null--Unicode编码,一个字符占两个字节,宽字符编码格式
drop database 数据库名
go
修改数据库:
alter database 数据库名
add/modify/remove(添加,修改,移除) file
(
)
go
检查表是否存在:
if exists(select * from sysobjects where name='表名')
drop table 表名
go
给表添加约束:
create table 表名
(
id int not null primary key,
sex nchar(2) not null check(sex='男' or sex='女'),
address varchar(100) default('福州市')

)
go
若在创建表时忘了添加约束,这时候就可以通过这种方式
alter table 表名
add constraint ck_sex check(sex='男' or sex='女')
go
alter table 表名
add constraint df_address default('福州市')for address
go
删除已有的约束:
alter table 表名
drop constraint df_address
go
alter table 表名
add constraint pk_test primary key(字段名1,字段名2...)

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值