Application and principles of database
VB.NET 程序设计实验报告
? (数据库基本表的查询、索引与视图的定义、删除、修改)
Application and principles of database
数据库基本表的查询、索引与视图的定义、删除、修改
1.实验项目的目的和任务:使学生熟悉SQL server的企业管理器的用法,初步了解SQL server查询分析器的使用
方法,熟悉SQL server的常用数据类型,加深对SQL和SQL语言的查询语句的理解。熟悉掌握简单表,索引与视图的创建与修改。 2.设计分析
需要给出一个最大值、一个最小值、产生随机数的数目,并且随机数不能重复。
3.源程序代码
create database shiyan
on(name='shiyanpei',filename='e:\\shiyanpei.mdf') log on (name='shiyanpp',filename='e:\\shiyanpp.ldf')
create table student
(sno char(10) primary key, sname varchar(12), sage int,
sex char(1)) //建立一个学生表
alter table student
add sdept varchar(50) not null //增加列
alter table student
drop column sdept //删除列
alter table student
alter column sname varchar(14)//修改列属性
create table course (sno char(10), cno char(2),
primary key (sno,cno),
grade decimal(5,2))//建立一个课程表
alter table course
drop PK__course__7E6CC920//删除主码
alter table course
add constraint pk_snocon primary key(sno,cno)// 实体完整性约束
alter table course
add constraint ck_grade check(grade>=0 and grade<=100)//用户自定义约束
alter table course add constraint fk_sno
foreign key (sno) references student(sno) //参照完整性约束外码
alter table student
add constraint uq_sname unique(sname)//唯一约束
alter table student
alter column sage int not null //非空约束
create index ix_sage on student(sage asc) //创建索引 drop index ix_sage on student //删除索引
create view v_student
as select * from student where sex='m' 创建视图
4运行结果如图所示
1
Application and