sql 创建表+约束

use lyb
go
if exists (select * from sysobjects where name='student')
drop table student
create table student
(
 id int identity(1,1),
 stuNumber int not null,
 stuName varchar(60) not null,
 password varchar(60) not null,
 sex nvarchar(50) not null,
 birthday smalldatetime ,
 address varchar(60)
)


alter table student
 add constraint pk_id primary key(id),
  constraint df_password default(888888) for password,
  constraint ck_password check(len(password)>6),
  constraint ck_sex check(sex='男' or sex='女')

 

select * from student
insert into student values(1,'xxx','1234567','男','','')
insert into student values(1,'xxx','8811270','男','','湖北省广水市吴店镇东塆村四组')
update student set stuNumber=2 where id=2
select stuNumber as '学号' ,stuName as '姓名' ,password as '密码' from student


 

posted on 2010-04-25 12:38  sdh  阅读(171)  评论(0)    收藏  举报

导航