数据库原理上机实验代码及截图
- 格式:doc
- 大小:2.30 MB
- 文档页数:36
数据库上机实验报告1一、实验目的:理解SQL Server数据库的存储结构,掌握SQL Server数据库的建立方法和维护方法。
二、实验内容:在SQL Server环境下建立数据库和维护数据库。
三、程序源代码:--1CREATE DATABASE test1ON(NAME=test1_dat,FILENAME='f:\DB\data\test1dat.mdf',SIZE= 10,MAXSIZE= 50,FILEGROWTH= 5 )LOG ON(NAME=order_log,FILENAME='f:\DB\data\test1log.ldf',SIZE= 5MB,MAXSIZE= 25MB,FILEGROWTH= 5MB)--2create database test2onprimary(name=test2_dat1,filename='f:\DB\data\test2dat1.mdf'),(name=test2_dat2,filename='f:\DB\data\test2dat2.ndf'),(name=test2_dat3,filename='f:\DB\data\test2dat3.ndf')log on(name=test2_log1,filename='f:\DB\data\test2log1.ldf'),(name=test2_log2,filename='f:\DB\data\test2log2.ldf')--3create database test3onprimary(name=test3_dat1,filename='f:\DB\data\test3dat1.mdf'),(name=test3_dat2,filename='f:\DB\data\test3dat2.mdf'),filegroupg2(name=test3_dat3,filename='d:\DB\data\test3dat3.ndf'),(name=test3_dat4,filename='d:\DB\data\test3dat4.ndf'),filegroupg3(name=test3_dat5,filename='e:\DB\data\test3dat5.ndf'),(name=test3_dat6,filename='e:\DB\data\test3dat6.ndf')log on(name=test3_log,filename='f:\DB\data\test3log.ldf')--4alter database test1add file(name=test1new_dat,filename='f:\DB\data\test1newdat.ndf',size=5MB)--5alter database test1modify file(name=test1_dat,size=15MB)--6dropdatabasetest3四、实验数据、结果分析:若没有指定size,则默认为1MB,没有指定Maxsize,文件可以增长到磁盘满为止,没有指定Filegrowth,则默认为10%。
- 《数据库原理》上机实验报告2017年11月一、实验目的与要求:●熟练使用SQL定义子语言、操纵子语言命令语句●掌握关系模型上的完整性约束机制●掌握一定的数据库管理技术●能完成简单的数据库应用开发二、实验容1、实验一到实验十七(一)数据定义子语言实验(2学时)实验1:利用SQL语句创建Employee数据库代码如下:create database Employee;运行结果:实验2:利用SQL语句在Employee数据库中创建人员表person、月薪表salary及部门表dept, 暂不定义外键约束。
要求:按表1、表达、表3中的字段说明创建表1 person表结构表2 salary表结构表3 dept表结构代码如下:create table person(P_no char(6) not null primary key,P_name varchar(10) not null,Sex char(2) not null,Birthdate datetime null,Prof varchar(10) null,Deptno char(4) not null);create table salary(P_no char(6) not null primary key,Base dec(5) null,Bonus dec(5) null,Fact dec(5) null,Month int not null);create table dept(Deptno char(4) not null primary key,Dname varchar(10) not null);运行结果:(二)数据操纵子语言实验(4学时)实验3:利用SQL语句向表person、salary和dept中插入数据。
要求:按表4、表5、表6中的数据插入。
表4 表person中的数据P_no P_name Sex BirthDate Prof Deptno 000001 王云男1973-4-7 中级0001 000002 志文男1975-2-14 中级0001代码如下:insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000001','王云','男','1973-4-7','中级','0001')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000002','志文','男','1975-2-14','中级','0001')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000003','浩然','男','1970-8-25','高级','0002')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000004','廖小玲','女','1979-8-6','初级','0002')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000005','梁玉琼','女','1970-8-25','中级','0003')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000006','罗向东','男','1979-5-11','初级','0003')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000007','尚家庆','男','1963-7-14','高级','0003')运行结果:表5 表salary中的数据P_no Base Bonus Fact S_month 000001 2100 300 1000002 1800 300 1000003 2800 280 1000004 2500 250 1000005 2300 275 1000006 1750 130 1000007 2400 210 1代码如下:insert into salary (P_no,Base,Bonus,Fact,Month) values ('000001',2100,300,2100+300,1) insert into salary (P_no,Base,Bonus,Fact,Month) values ('000002',1800,300,1800+300,1) insert into salary (P_no,Base,Bonus,Fact,Month) values ('000003',2800,280,2800+280,1) insert into salary (P_no,Base,Bonus,Fact,Month) values ('000004',2500,250,2500+500,1) insert into salary (P_no,Base,Bonus,Fact,Month) values ('000005',2300,275,2300+275,1) insert into salary (P_no,Base,Bonus,Fact,Month) values ('000006',1750,130,1750+130,1) insert into salary (P_no,Base,Bonus,Fact,Month) values ('000007',2400,210,2400+210,1)运行结果:表6 表dept中的数据Deptno Dname0001 人事部0002 财务部0003 市场部代码如下:insert into dept (Deptno,Dname) values ('0001','人事部')insert into dept (Deptno,Dname) values ('0002','财务部')insert into dept (Deptno,Dname) values ('0003','市场部')运行结果:实验4:(1)利用SQL语句修改表中的数据。
数据库原理上机实验报告数据库实验报告2.1 实验目的通过实习了解掌握数据库和数据表的两种创建方式: 1)通过数据库管理系统软件提供的管理界面完成数据库和数据表的创建;2)通过SQL 语言完成数据库和数据表的创建。
2.2 实验平台1. 操作系统:Windows 7、WindowsXP、Windows Server2003/2008。
2. 数据库管理系统:根据实际情况,自己选择Oracle 或SQL Server 或MySQL 中的一种数据管理管理系统软件。
2.3 实验内容1.采用SQL Server 的Management Studio,或者Oracle 的控制台,或者MySQL 的Workbench 建立一个数据库University,其中包括6 个数据表:a)系的信息表Department(Dno,Dname,Daddress);b) 学生信息表Student(Sno, Sname, Ssex, Sage, Dno);c) 教师信息表Teacher (Tno, Tname, Ttitle, Dno);d) 课程信息表Course (Cno, Cname, Cpno, Ccredit);e) 学生选课表SC(Sno,Cno,Grade);f) 教师授课表TC(Tno,Cno,Site)。
上面加有下划线的为该表的关键码,Dno 表示系的编号,Dname 表示系名,Daddress 表示系所在的办公地址;Sno 表示学号,Sname 为学生姓名,Ssex 为学生性别,Sage 学生年龄;Tno 表示教师编号,也即职工号,Tname 表示教师姓名,Ttitle 表示教师职称;Cno 表示课程编号,Cname 表示课程名称,Cpno 先导课程编号,Ccredit 课程学分;Grade 表示每个学生的每一门课的成绩;Site 表示授课地点。
代码:/*系的信息表Department(Dno,Dname,Daddress)*/create table Department(Dno number(10),Dname varchar2(50),Daddress varchar2(50),primary key (Dno));/*学生信息表Student(Sno, Sname, Ssex, Sage, Dno)*/create table Student(Sno char(11) ,Sname varchar2 (50),Ssex char(2),Sage number(10) ,Dno number(10),primary key (Sno),foreign key (Dno) references Department(Dno));/*教师信息表Teacher (Tno, Tname, Ttitle, Dno)*/create table Teacher(Tno number(10) primary key,Tname varchar2 (50),Ttitle varchar2 (50),Dno number(10) ,foreign key (Dno) references Department(Dno));/*课程信息表Course (Cno, Cname, Cpno, Ccredit)*/ create table Course(Cno number(10) primary key ,Cname varchar2 (50),Cpno number(10) ,CCredit number(10),foreign key(Cpno) references Course(Cno));/*学生选课表SC(Sno,Cno,Grade)*/create table SC(Sno char(11),Cno number(10),Grade number(10),primary key(Sno, Cno),foreign key(Sno) references Student(Sno),foreign key (Cno) references Course(Cno) );/*教师授课表TC(Tno,Cno,Site)*/ create table TC(Tno number(10) ,Cno number(10),Site varchar2(50),primary key (Tno,Cno),foreign key(Tno) references Teacher(Tno), foreign key (Cno) references Course(Cno) );2.采用SQL 语言删除步骤1 中建立的数据表和数据库;代码:drop table SC;drop table TC;drop table Course;drop table Teacher;drop table Student;drop table Department;3.采用SQL 语言建立数据库DB 和其中的6 个数据4.采用SQL 语句为Student 表的Sname 建立唯一索引。
数据结构上机实验源代码栈的应用十进制数转换为八进制数,逆序输出所输入的数实验代码://stack.h,头文件class stack{public:stack();bool empty()const;bool full()const;error_code gettop(elementtype &x)const;error_code push(const elementtype x);error_code pop();private:int count;elementtype data[maxlen];};stack::stack(){count=0;}bool stack::empty()const{return count==0;}bool stack::full()const{return count==maxlen;}error_code stack::gettop(elementtype &x)const{if(empty())return underflow;else{x=data[count-1];return success;}}error_code stack::push(const elementtype x){if(full())return overflow;data[count]=x;count++;return success;}error_code stack::pop(){if(empty())return underflow;count--;return success;}//主程序#include<iostream.h>enum error_code{overflow,underflow,success};typedef int elementtype;const int maxlen=20;#include"stack.h"void read_write() //逆序输出所输入的数{stack s;int i;int n,x;cout<<"please input num int n:";cin>>n;for(i=1;i<=n;i++){cout<<"please input a num:";cin>>x;s.push(x);}while(!s.empty()){s.gettop(x);cout<<x<<" ";s.pop();}cout<<endl;}void Dec_to_Ocx(int n) //十进制转换为八进制{stack s1;int mod,x;while(n!=0){mod=n%8;s1.push(mod);n=n/8;}cout<<"the ocx of the dec is:";while(!s1.empty()){s1.gettop(x);cout<<x;s1.pop();}cout<<endl;}void main(){int n;// read_write();cout<<"please input a dec:";cin>>n;Dec_to_Ocx(n);}队列的应用打印n行杨辉三角实验代码://queue.hclass queue{public:queue(){count=0;front=rear=0;}bool empty(){return count==0;}bool full(){return count==maxlen-1;}error_code get_front(elementtype &x){if(empty())return underflow;x=data[(front+1)%maxlen];return success;}error_code append(const elementtype x){if(full())return overflow;rear=(rear+1)%maxlen;data[rear]=x;count++;return success;}error_code serve(){if(empty())return underflow;front=(front+1)%maxlen;count--;return success;}private:int count;int front;int rear;int data[maxlen];};//主程序#include<iostream.h>enum error_code{overflow,underflow,success};typedef int elementtype;const int maxlen=20;#include"queue.h"void out_number(int n) //打印前n行的杨辉三角{int s1,s2;int i;int j;int k;queue q;for(i=1;i<=(n-1)*2;i++)cout<<" ";cout<<"1 "<<endl;q.append(1);for(i=2;i<=n;i++){s1=0;for(k=1;k<=(n-i)*2;k++)cout<<" ";for(j=1;j<=i-1;j++){q.get_front(s2);q.serve();cout<<s1+s2<<" ";q.append(s1+s2);s1=s2;}cout<<"1 "<<endl;q.append(1);}}void main(){int n;cout<<"please input n:";cin>>n;out_number(n);}单链表实验实验目的:实验目的(1)理解线性表的链式存储结构。
设有一学籍管理系统,其数据库名为“EDUC”。
初始大小为 10MB,最大为50MB,数据库自动增长,增长方式是按5%比例增长;日志文件初始为2MB,最大可增长到5MB,按1MB增长。
数据库的逻辑文件名为“student_data”, 物理文件名为“student_data.mdf,存放路径为“E:\sql_data”(注意:此文件名必须已经建立的前提下才可以此操作)。
日志文件的逻辑文件名为“student_log”, 物理文件名为“student_log.ldf”,存放路径为“E:\sql_data”。
四.实验步骤1.使用SQL Server Management Studio(简称SSMS)创建数据库。
(1)启动SSMS在开始菜单中:所有程序-SQL Server 2005 -SQL Server Management Studio单击“连接”按钮,便可以进入【SQL Server Management Studio】窗口。
如果身份验证选择的是“混合模式”,则要输入sa的密码。
(2)建立数据库在“对象资源管理器”窗口,建立上述数据库EDUC。
在数据库节点上右击选择新建。
同时建立一个同样属性的数据库EDUC1。
2. 使用向导删除上面建立的数据库。
用SSMS删除建立的数据库EDUC。
3、数据库的分离将刚建好的数据库分离出来,即点击新建的EDUC——任务——分离,将删除连接和更新打一个钩,然后点击确定。
如图所示:4、数据分离出来之后可以附加进去。
即右击数据库——附加——点击添加按钮,找到数据库文件.mdf所存放的路径,然后点击确定,即可以将我们刚所创建的文件添加回去。
五.实验总结通过本次实验,我熟悉了SQL Server 中SQL Server Management Studio的环境,了解了SQL Server 数据库的逻辑结构和物理结构,掌握使用向导创建和删除数据库的方法。
加深了对数据库的认识和理解。
实验2 数据查询(1)查询性别为“男”的所有学生的名称并按学号升序排列。
SELECT SnameFROM StudentsWHERE Ssex='男'ORDER BY Sno(2)查询学生的选课成绩合格的课程成绩,并把成绩换算为积分。
积分的计算公式为:[1+(考试成绩-60)*0.1]*Ccredit。
考试成绩>=60 否则=0SELECT Sno, Tno, o, Score, 'Point of Score',CONVERT(FLOAT(1), (Score-60)*0.1*Ccredit+Ccredit)FROM Courses, ReportsWHERE Score>=60 AND o=oUNIONSELECT Sno, Tno, o, Score, 'Point of Score', 0FROM Courses, ReportsWHERE o=o AND (Score < 60 OR Score ISNULL)(3)查询学分是3或4的课程的名称。
SELECT CnameFROM CoursesWHERE Ccredit IN('3','4')(4)查询所有课程名称中含有“算法”的课程编号。
SELECT CnameFROM CoursesWHERE Cname LIKE '%算法%'/*查询得到算法分析与设计、数据结构与算法分析*/(5)查询所有选课记录的课程号(不重复显示)。
SELECT DISTINCT Cno FROM Reports(6)统计所有老师的平均工资。
SELECT A VG(Tsalary) FROM Teachers(7)查询所有教师的编号及选修其课程的学生的平均成绩,按平均成绩降序排列。
SELECT Tno,A VG(Score)FROM ReportsGROUP BY TnoORDER BY A VG(Score) DESC(8)统计各个课程的选课人数和平均成绩。
《数据库原理及应用》上机实验报告表(1)利用企业管理器修改(2)利用T-SQL语句修改五、用户自定义完整性的规则(1)利用企业管理器创建右键单击“规则”(2)利用T-SQL语句创建Create rule age_rule as @agescope between 19 and 24Drop rule age_rule六、用户自定义完整性的默认(1)利用企业管理器创建右键单击“默认”(2)利用T-SQL语句创建Create default ssex_default as ‘男’Drop default ssex_default(3)利用存储过程绑定规则Sp_binddefault ssex_default,’student.ssex’Sp_unbindrule ’student.ssex’(4)使用create table声明默认值Create table student(sno char(10) primary key,ssex char(2) default ‘男’)insert into student (sno)values(‘2007141101’)七、用户自定义完整性的约束(1)利用企业管理器创建(2)利用T-SQL语句创建使用create table语句在建立新表的同时定义约束Unique check(域完整性)使用alter table语句向已经存在的表中添加约束八、触发器(1)利用企业管理器创建右键单击“表”,在快捷菜单中选择“所有任务|管理触发器”(2)利用T-SQL语句创建创建一个触发器,当向表中插入一个数据后,就把表中的所有数据显示出来。
Create trigger sample1On studentFor insertAsselect * from studentdrop trigger sample1在student表中添加一条记录后,显示出INSERTED表的内容Create trigger sample2On studentFor insertAsselect * from inserted在student表中删除一条记录后,显示出DELETED表的内容Create trigger sample3On studentFor deleteAsselect * from deletedgodelete from student where sno=’2007141101’在student表中更新一条记录后,显示出INSERTED表和DELETED表的内容Create trigger sample4On studentFor updateAsselect * from insertedselect * from deletedgoupdate student set ssex=’男’where sno=’2007141101’alter triggerdrop trigger。
数据库原理与设计大作业源代码(1) 用户登录界面运行超市管理信息系统后,首先进入用户登录界面,用户输入用户名和密码后,系统进行验证,验证通过进入程序的主界面。
在进行系统登录过程中,登录模块将调用数据库里的用户信息表,并对用户名和密码进行验证,只有输入了正确的账号和密码后,系统登录才会成功。
在登录模块中,对系统的尝试登录次数进行了限制,禁止用户无终止的进行系统登录尝试,在本系统中,当用户对系统的三次登录失败后,系统将自动机制登录,突出登录模块。
并在输入了错误的或者是不存在的账户和密码时,系统会给出出错信息提示,指明登录过程中的错误输入或者错误操作,以便用户进行正确的登录。
登录界面如图5-2所示。
图5-2 登录界面主要实现代码如下://登录private void radBtnOk_Click(object sender, EventArgs e){try{if (radTxtBoxUser.Text.Trim() == ""){this.radLbInfo.Text = "请输入您的用户名!";}else if (radTxtBoxPsw.Text.Trim() == ""){this.radLbInfo.Text = "请输入您的密码!";}else{commandUnit com = new commandUnit();string str = @"select * from UserInfo where loginNo = '" + radTxtBoxUser.Text.ToString() + "'";DataTable table = com.GetDataSet(str);if (table.Rows.Count <= 0){this.radLbInfo.Text = "用户名不存在!";radTxtBoxUser.Text = "";radTxtBoxPsw.Text = "";return;}str = @"select * from UserInfo where loginNo = '" + radTxtBoxUser.Text.ToString() + "' and passWord = '" + radTxtBoxPsw.Text.ToString() + "'";DataTable tableUser = com.GetDataSet(str);if (tableUser.Rows.Count > 0){_currentUser = radTxtBoxUser.Text;_currentPsw = radTxtBoxPsw.Text;IsLogin = true;this.Close();}else{this.radLbInfo.Text = "密码错误!";radTxtBoxPsw.Text = "";}}}catch (System.Exception ex){throw ex;}}(2) 主界面系统登录成功后,进入主界面菜单。
朱彦荣数据库实验所有代码与截图11.1CreateDatabase EmployeeOnPrimary(Name=Empdat1,Filename='E:\data\Empdat1.mdf',Size= 10MB,MaxSize= 50MB,FileGrowth= 5MB)Log On(Name=Emplog,Filename='E:\data\Emplog.ldf',Size= 5MB,MaxSize= 25MB,FileGrowth= 5%)1.增加次数据文件alterdatabase Employeeaddfile(Name=Empdat2,Filename='E:\data\Empdat2.ndf',Size= 5MB,MaxSize= 25MB,FileGrowth= 2MB)--2.修改主文件alterdatabase EmployeeMODIFYfile(Name=Empdat1,maxsize=80MB)11.2创建四表。
createtable person20132184(P_no char(6)notnull primarykey,P_name varchar(10)notnull,Sex char(2)notnull,BirthDate datetime null,Date_hired datetime notnull,Deptname varchar(10)notnull default'培训部',P_boss char(6)null,constraint birth_hire_check20132184check (Birthdate<Date_hired));--dec 和dec(p, s)。
p(精度)指定小数点左边和右边可以存储的十进制数字的最大个数。
精度必须是从1 到最大精度之间的值。
最大精度为38。
数据库系统原理上机实验预备知识一、本实验指导书采用的数据库例子(见本课程参考用书《数据库系统概论》(第三版)P59) Student-Course-SC数据库:一个学生可以修多门课程,一门课程可以被多个学生选修,则学生、课程之间的E-R图如下:转化为关系数据模型:Student(Sno, Sname,Ssex,Sage,Sdept)Course(Cno,Cname,Cpno,Ccredit)SC(Sno,Cno,Grade)物理数据模型如下:数据库名MySC表名Student实体名学生属性名列名(字段名)数据类型长度允许空描述学号Sno char 5否学生的学号(主键)姓名Sname char 8否学生的姓名性别Ssex char 2学生的性别年龄Sage:tinyint l学生的年龄所在系Sdept char 2学生所在系数据库名MySC表名Course实体名课程属性名列名(字段名)数据类型长度允许空描述课程号Cno char 1否课程的编号(主键)课程名Cname char 20否课程的名称先行课Cpno char L课程先行课的编号学分Ccredit tinyint 1课程的年学分数据库名MySC表名SC实体名学生选课属性名列名(字段名)数据类型长度允许空描述学号Sno char 5否学生的学号(外键)课程号Cno char 3否谍程的编号(外键)成绩Grade tinyint 1学生该门课的成绩主键 (Sno.Cno)索引:对表Course中的字段Ccredit创建降序索引,索引名为IX_Course_Ccredit;检查约束:对表Student中的字段Sno创建检查约束LEN(Sno)>4,约束名为CK_Student_Sno;图表:建立名为“SC_Diagrame1”的图表,反映“SC”、“Student”、“Course”三张表间的备份和维护计划:为自己所建立的数据库创建备份和维护计划。
《数据库原理》上机实验报告2017年11月一、实验目的与要求:●熟练使用SQL定义子语言、操纵子语言命令语句●掌握关系模型上的完整性约束机制●掌握一定的数据库管理技术●能完成简单的数据库应用开发二、实验容1、实验一到实验十七(一)数据定义子语言实验(2学时)实验1:利用SQL语句创建Employee数据库代码如下:create database Employee;运行结果:实验2:利用SQL语句在Employee数据库中创建人员表person、月薪表salary及部门表dept, 暂不定义外键约束。
要求:按表1、表达、表3中的字段说明创建表1 person表结构表2 salary表结构表3 dept表结构代码如下:create table person(P_no char(6) not null primary key,P_name varchar(10) not null,Sex char(2) not null,Birthdate datetime null,Prof varchar(10) null,Deptno char(4) not null);create table salary(P_no char(6) not null primary key,Base dec(5) null,Bonus dec(5) null,Fact dec(5) null,Month int not null);create table dept(Deptno char(4) not null primary key,Dname varchar(10) not null);运行结果:(二)数据操纵子语言实验(4学时)实验3:利用SQL语句向表person、salary和dept中插入数据。
要求:按表4、表5、表6中的数据插入。
表4 表person中的数据P_no P_name Sex BirthDate Prof Deptno 000001 王云男1973-4-7 中级0001 000002 志文男1975-2-14 中级0001 000003 浩然男1970-8-25 高级0002 000004 廖小玲女1979-8-6 初级0002 000005 梁玉琼女1970-8-25 中级0003 000006 罗向东男1979-5-11 初级0003 000007 肖家庆男1963-7-14 高级0003 000007 肖家庆男1963-7-14 高级0003 代码如下:insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000001','王云','男','1973-4-7','中级','0001')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000002','志文','男','1975-2-14','中级','0001')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000003','浩然','男','1970-8-25','高级','0002')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000004','廖小玲','女','1979-8-6','初级','0002')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000005','梁玉琼','女','1970-8-25','中级','0003')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000006','罗向东','男','1979-5-11','初级','0003')insert into person (P_no,P_name,Sex,Birthdate,Prof,Deptno) values ('000007','尚家庆','男','1963-7-14','高级','0003')运行结果:表5 表salary中的数据P_no Base Bonus Fact S_month 000001 2100 300 1000002 1800 300 1000003 2800 280 1代码如下:insert into salary (P_no,Base,Bonus,Fact,Month) values ('000001',2100,300,2100+300,1)insert into salary (P_no,Base,Bonus,Fact,Month) values ('000002',1800,300,1800+300,1)insert into salary (P_no,Base,Bonus,Fact,Month) values ('000003',2800,280,2800+280,1)insert into salary (P_no,Base,Bonus,Fact,Month) values ('000004',2500,250,2500+500,1)insert into salary (P_no,Base,Bonus,Fact,Month) values ('000005',2300,275,2300+275,1)insert into salary (P_no,Base,Bonus,Fact,Month) values ('000006',1750,130,1750+130,1)insert into salary (P_no,Base,Bonus,Fact,Month) values ('000007',2400,210,2400+210,1)运行结果:表6 表dept中的数据Deptno Dname0001 人事部0002 财务部0003 市场部代码如下:insert into dept (Deptno,Dname) values ('0001','人事部')insert into dept (Deptno,Dname) values ('0002','财务部')insert into dept (Deptno,Dname) values ('0003','市场部')运行结果:实验4:(1)利用SQL语句修改表中的数据。
要求:将salary表中工号为000006的员工工资增加为1800元,奖金增加为160元。
代码如下:update salaryset Base=1800,Bonus=160,Fact=1800+160where P_no='000006'运行结果:(2)利用SQL语句删除表中的数据。
要求:删除 salary表中工号为000007的员工数据。
代码如下:deletefrom salarywhere P_no='000007'(3)利用SQL语句查询person表中的所有数据。
代码如下:select *from person运行结果:实验5:(1)创建视图要求:创建员工视图PersonView,包含员工的所有信息,并调用视图代码如下:create view PersonView asselectperson.P_no,P_name,Sex,Birthdate,Prof,person.Deptno,Base,Bonus,Fa ct,Month,Dnamefrom person,salary,deptwhere person.Deptno=dept.Deptno and salary.P_no=person.P_no select * from PersonView运行结果:(2)删除视图要求:将视图PersonView删除代码如下:drop view PersonView运行结果:实验6:条件查询要求:(1)查询person表中所有不重复的职称。
(2)查询person表中职称为中级的所有员工数据。
(3)查询person表中具有高级职称的男员工信息。
(4)查询person表中为王云、志文、罗向东的员工数据。
代码及运行结果如下:(1)select distinct Prof from person(2)select * from person where Prof='中级'(3)select * from person where Prof='高级' and Sex='男'(4)select * from person where P_name in ('王云','志文','罗向东')实验7:使用ORDER BY排序要求:利用SQL语句将工号在000003和000006之间的员工的月收入按实发工资升序排序。
代码如下:select * from salary where P_no between '000003' and '000006' order by Fact asc运行结果:实验8:利用SQL语句查询各部门的实发工资总数。
代码如下:select dept.Dname,sum(Fact) as "部门实发工资总数"from person,salary,deptwhere person.Deptno=dept.Deptno and salary.P_no=person.P_no group by dept.Dname运行结果:实验9:利用SQL语句查询人事部所有员工信息。