您的位置:首页 > 数据库

T-SQL数据库规则约束及默认值设置学习笔记

2007-04-16 14:06 399 查看
create database test1
go
use test1
create table table1
(
book_ID int primary key not null,
book_name varchar(50) not null,
book_price varchar(100) not null,
book_type varchar(50) not null,
master_phone varchar(100) not null
)
go
create default master_phone as '(000)00000000'
go
exec sp_bindefault master_phone,'table1.master_phone'
insert into table1 values('1','仙剑奇侠传','50','科幻小说','(028)81776327')
insert into table1 (book_ID,book_name,book_price,book_type) values('2','网络经济学','80','网络教材')
select * from table1
go
--默认值设置成功!
create rule book_type_rule as @book_type in ('科幻小说','网络教材','文学读本','恐怖小说','言情小说')
go
exec sp_bindefault book_type_rule,'table1.book_type'
go
--创建规则约束成功!
--打完收功....
drop table table1
drop database test1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: