--1.创建一个学生信息表StuInfo
use jwt
go
create table StuInfo
(学号 nchar(20) not null,
--constraint 学号 primary key clustered
--check (学号 like '31201709062[0-9][0-9]'),
姓名 nchar(8) not null,
性别 nchar(2) null,
年龄 int null,
电话号码 nchar(11) null
-- primary key(学号)
)
--2.修改姓名字段长度为80
use jwt
go
alter table StuInfo
alter column 姓名 nchar(80) null
--3.修改性别的检查约束为男女值(要修改此约束,必须先将其删除,然后重新创建)
use jwt
go
alter table StuInfo
drop column 性别
alter table StuInfo
add 性别 nchar(2) null
constraint 性别 check (性别 in( '男','女'))
--4.插入两行学生记录
use jwt
go
insert into StuInfo(学号,姓名,性别,年龄,电话号码)
values('3120170906210','jwt','男','18','10086')
insert into StuInfo(学号,姓名,性别,年龄,电话号码)
values('3120170906211','jwta','女','18','1008611')
select * from StuInfo --查看表
--5.修改其中一个同学姓名为Bob
use jwt
go
update StuInfo
set 姓名='Bob' where 姓名='jwta'
select * from StuInfo --查看表
--6.删除Bob同学
use jwt
go
delete StuInfo
where 姓名='Bob'
select * from StuInfo --查看表
--7.删除表
use jwt
go
drop table StuInfo