实验二(数据库基本表的查询、索引与视图的定义、删除、修改)

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 principles of database

5实验总结

通过具体的上机实践操作,学会了用VB.NET语言做随机生成数,激发了学习vb.net课程的兴趣。

(1) Label(标签)控件主要用于显示(输出)文本信息。除了显示文本外,label控件还可以使用image属

性显示图像,或使用imagelist和imageindex属性组合显示图像。

(2) TextBox(文本框)控件用于输入文本信息。TextBox控件一般用于显示或输入单行文本,还可以实现限

制输入字符数、密码字符屏蔽、多行编辑、大小写转换等功能。

(3) Button(按钮)控件用于执行用户的单击操作。如果焦点位于某个Button,则可以使用鼠标、enter键

或空格键单击该按钮。当用户单击按钮时,即调用Click事件处理程序。Button上显示的文本通过text属性进行设置,也可以使用image和imagelist属性显示图像。

2

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4