在线咨询
QQ咨询
服务热线
服务热线:13125520620
TOP

表的相关操作-数据库

发布时间:2011-11-12 浏览:4652

 

--第二课 表的相关操作
--在数据库上建立一个表
--例子:建立一个“学生”表student,它由学号sno,姓名sname,性别ssex,年龄sage,所在系sdept五个属性组成。
--      其中学号不能为空,值是唯一的,并且姓名取值也唯一不能为空,年龄在0~150之间
create table student
(sno int not null unique,
sname varchar(20) unique check(sname<>''),
ssex bit,
sage int check(sage<150 and sage>=0),
sdept varchar(20))
go
select * from student
go

create table student1
(sno int not null unique,
sname varchar(20) unique not null,
ssex bit,
sage int check(sage<150 and sage>=0),
sdept varchar(20))
go
select * from student1
go

create table student2
(sno int not null unique,
sname varchar(20) not null unique ,
ssex bit,
sage int check(sage<150 and sage>=0),
sdept varchar(20))
go
select * from student2
go

CREATE TABLE XS
(学号 char(6) NOT NULL,
姓名 char(8) NOT NULL,
专业名 char(10) NULL,
性别 bit NOT NULL,
出生时间 smalldatetime NOT NULL, 
总学分 tinyint NULL,
备注 text NULL
)
GO

--修改列属性
ALTER TABLE XS
ADD
奖学金等级 tinyint NULL
GO
ALTER TABLE XS
ALTER COLUMN 出生时间 datetime
go

select * from xs
go

--修改记录
update xs
set 奖学金等级=2
where 姓名='李洁'
go 

--插入记录
insert
into student
values(2,'li',1,23,'')
go

insert
into student
values(3,'andy',1,23,'')
go
select * from student
go

TAG
软件定制,软件开发,瀚森HANSEN
0
该内容对我有帮助