1、1 先将4个表输入完成源程序如下:-1 创建供应商表CREATE TABLE S( SN CHAR(3), SNAME VARCHAR(20), CITY VARCHAR(20), PRIMARY KEY(SN);-2 创建零件表CREATE TABLE P( PN CHAR(3), PNAME VARCHAR(20), COLOR CHAR(4), WEIGHT INT, PRIMARY KEY(PN);-3 创建工程表CREATE TABLE J( JN CHAR(3), JNAME VARCHAR(20), PRIMARY KEY(JN);-4 创建供应关系表create table S
2、PJ(SN char(3) , PN char(3), JN char(3), QTY int , primary key(SN,PN,JN), foreign key(SN) references S, foreign key(PN) references P, foreign key(JN) references J);-5 插入数据 insert into S values(S1,SN1 , 上海) ;insert into SS2SN2 北京S3SN3 南京S4SN4 西安S5SN5 上海 insert into PP1PN1 红,12) ;P2PN2 绿,18) ;P3PN3 蓝,2
3、0) ;P4PN4 ,13) ;P5PN5 白,11) ;P6PN6 insert into JJ1JN1 J2JN2 广州J3JN3 武汉J4JN4 J5JN5 J6JN6 J7JN7 insert into SPJ,200) ;,700) ;,800) ;,30) ;,400) ;,500) ;,300) ;,100) ;,250) ;然后进行查询:1.select *from jwhere CITY=2SELECT PNFROM PWHERE WEIGHT= ( select MIN(WEIGHT) FROM P)3SELECT SNFROM SPJWHERE JN=4 AND PN=5
4、SELECT JNAME FROM J SPJWHERE JN IN( SELECT JN FROM SPJ WHERE SN= )6SELECT COLOR FROM P SPJWHERE PN IN( SELECT PN7SELECT S2.SN FROM SPJ S1,SPJ S2WHERE S1.JN=AND S2.JN IN( SELECT JN FROM SPJ S2 WHERE S2.JN=GROUP BY S2.SN 8SELECT SN FROM SPJ PAND PN IN( SELECT PN FROM P WHERE COLOR=GROUP BY SN 9FROM SP
5、J J FROM J WHERE CITY=10OR CITY=11FROM S JWHERE CITY IN( SELECT CITY FROM J WHERE CITY= )12SELECT PN FROM SPJ S WHERE SN IN( SELECT SN FROM S J WHERE CITY IN( GROUP BY PN13SELECT SPJ.PNFROM SPJ,S,Jwhere J.JN=SPJ.JN AND SPJ.SN=S.SN AND J.CITY=AND S.CITY=;14SELECT SPJ.JNFROM S,SPJ,JWHERE S.SN=SPJ.SN A
6、ND SPJ.JN=J.JN AND S.CITY!=J.CITYEXCEPTSELECT SPJJN=J.CITY;15SELECT JNFROM SPJWHERE SN NOT IN( SELECT SN FROM SEXCEPT );21FROM JWHERE JN NOT IN( SELECT J.JN FROM S,P,SPJ WHERE S.SN=SPJ.SN AND SPJ.PN=P.PN 天津 and p.color= );23UPDATE PSET COLOR=WHERE COLOR=UPDATE SPJ SET SN=s8WHERE SN=s6 AND JN=j4DELET
7、E s2DELETEFROM SINSERT INTO JVALUES(j8JN8江西INTO Ss9SN9INSERTInto SPJp4,200);五、实验结果创建的数据库为2.3.4.5.6.7.8.9.10.11.12.13.14.15.21.23.六、实验体会在本次实验中,我已经了解查询、更新的概念和方法,查询的的关键字为select,更新的为update。并且掌握查询分析器或企业管理器中执行SELECT操作和更新数据操作的方法;掌握SELECT语句在单表查询中的应用;掌握SELECT语句在多表查询中的应用;掌握SELECT语句在复杂查询中的使用方法。掌握INSERT、UPDATE、DELETE语句在更新中的应用。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1