广东工业大学SQL编程报告1.docx
《广东工业大学SQL编程报告1.docx》由会员分享,可在线阅读,更多相关《广东工业大学SQL编程报告1.docx(12页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、大作业名称:数据库的定义、建立与维护实验目的与要求使用SQL语言实现数据库的创建、删除;基本表的创建、删除、更新工作。必须给出完整的SQL源码,并以截图的形式表现出SQL语句的运行是否成功。二、SQL源码及运行结果1 .定义数据库.-创建数据库1 . CREATE DATABASE library_3119001063;I34 .-切换到 Library_3119001063 数据库 5,USE Library_3119001063;7 Q 127.0.0.1 3306 8.026 USER 0 library_3119001063 16k7 Q 127.0.0.1 3306 8.026 US
2、ER 0 library_3119001063 16kS Library_3119001063.sql .* Active Connection1-查看现有的数据库 ExecuteSHOW Databases;2 -创建数据库 Execute 5 CREATE DATABASE library_3119001063; 6CREATE DATABASE library_3119001063中Q输入以据回CREATE DATABASE library_3119001063Affected Rows: 1127.0.0.1 3306 8.026 USER 0 library_3119001063 1
3、6kS Library_3119001063.sql .5 CREATE DATABASE library_3119001063;67-切换到 Library_3119001063 数据库 Execute 8 USE Library_3119001063;9 一创建表 Execute11 CREATE TABLE bookUSE Library_3119001063中 白输入以搜索数据USE Library_3119001063Affected Rows: 02.定义下列数据库基本表-创建表1. CREATE TABLE book(bno CHAR(8) PRIMARY KEY NOT NUL
4、L,2. category VARCHAR(10) NOT NULL,title VARCHAR(40) NOT NULL,3. publisher VARCHAR(30) NULL,pub_year YEAR NOT NULL,4. author CHAR(20),price DEC工MAL(5,2) NOT NULL 10);11.12. CREATETABLE card13. (eno CHAR(7) PRIMARY KEY NOT NULL,14. pname CHAR(8) NOT NULL,15. .department VARCHAR(5),16. ctype char(l) N
5、OT NULL CHECK (ctype 工N(TJGJUJF)17. );18.19. (eno CHAR(7) PRIMARY KEY NOT NULL,20. pname CHAR(8) NOT NULL,21. .department VARCHAR(5),22. ctype char(l) NOT NULL CHECK (ctype 工N(TJGJUJF)23. );24.25. CREATE TABLE borrow26. (eno CHAR(7),27. bno CHAR(8),28. borrow_date DATE NOT NULL,29. return_date DATE,
6、24.CONSTRAINTC2PRIMARYKEY(cno,bno).25.CONSTRAINTC3FOREIGNKEY(cno)REFERENCEScard(cno),26.CONSTRAINTC4FOREIGNKEY(bno)REFERENCESbook(bno)27.); USERv 0 library_3119001063 16k t = tables (1)10 CO book =views query 照 procedures 。functionsii121314151617181920-创建表 ExecuteCREATE TABLE book(bno CHAR(8) PRIMAR
7、Y KEY NOT NULL,category VARCHAR(10) NOT NULL, title VARCHAR(40) NOT NULL, publisher VARCHAR(30), pub_year YEAR NOT NULL, author CHAR(20), price DECIMAL(5,2) NOT NULL);E3 book XSELECT * FROM book LIMIT 100;中 (9)睦数ES中 (9)睦数ES bno . category . char(8) varchar(10) 个J耗时:6ms 共。条author , price char(20) dec
8、imal author , price char(20) decimal , title . publisher . , pub_year -varchar(40) varchar(30) year V . 127.0.0.1 3306 8.026s Library_3119001063.sql .XOUI XCC 。二 LJMSLl Jj 4/ IMV NULL USER19);v0 library_311900106332k20 = tables (2)A Execute Q book21CREATETABLE card卬 card三口22(eno CHAR(7) PRIMARY KEY
9、NOT NULL,、_ . 123pname CHAR(8) NOT NULL,views24department VARCHAR(5), query25ctype char(l) NOT NULL CHECK (ctype IN(1,G,U,F) 电 procedures26); 0 functions27 Execute 28CREATE TABLE borrow?9(eno CHAR(7).由 cardXSELECT * FROM card LIMIT 100;4*白输入以赚数据由COG)向图个J 耗时:6ms 共。条C x eno . pname department ,ctype .
10、char(7) char(8) varchar(5) char(1) v . 127.0.0.1 3306 8.026S Library_3119001063.sql . USER- Executev 0 library_3119001063 48k/ 28 CREATE TABLE borrowy = tables 29(eno CHAR(7), 印 book阳bn。CHAR(8),. m .一 e31borrow date DATE NOT NULL. ULI borrow= L3上 一二132return date DATE,1 卬 card33CONSTRAINTC2PRIMARYKE
11、Y(cno,bno), =views34CONSTRAINTC3FOREIGNKEY(cno)REFERENCEScard(cno), query35CONSTRAINTC4FOREIGNKEY(bno)REFERENCESbook(bno) 每 procedures36); 0 functions3738-插入数据-插入Book表数据E2 borrow XSELECT * FROM borrow LIMIT 100;中台愉入以翦嘘。白国个。0耗时:2ms共。条C * eno * bno * borrow_date return_date .char(7) char(8) datedate3.
12、数据输入jl.-插入数据-插入Book表数据INSERT INTO book VALUES(b0001, eng.1, database systems, Springer1, 2016, ,John 28);2. INSERT INTO book VALUES(b0002eng., Operation systemsTaylor, 2018, Michael, 35);INSERT INTO book VALUES(b0003, sci.1, Advanced mathematics, MIT, 2021, Catherine* 15);5.INSERT INTO bookVALUES(b0
13、004sci. , Discrete mathematicsMIT, 2020,Peter, 22);6. INSERT INTO booknon: 40);7.INSERT INTO bookLisa, 19);8. INSERT INTO book25);9. INSERT INTO bookVALUES(* b0005 eng. , C language, Springer 2017, ShanVALUES(b0006,VALUES(b0007,VALUES(b0008,liter., Harry potter, Elseiver*, 2019,liter.Star wars, Else
14、iver1, 2018, Pimhis.Modern Chinese historyTaylor210. INSERT INTO book VALUES(1b0009,his. The second world war, Taylo21, Mark,32);11. INSERT INTObook VALUES(50010,eng., JAVA language, MIT, 2022,38);12.13.-插入数据-插入Card表数据14. INSERT INTOcard VALUES(,T001Li Yuan, auto, T1);15. INSERT INTOcard VALUES(T002
15、,Wang Li, auto, );16. INSERT INTOcard VALUES(T003,Zhang Qi, cs, T);17. INSERT INTOcard VALUES(,T004,Zhao Gao math, ,);18. INSERT INTOcard VALUES(16001,Wu Mi, auto, G);19. INSERT INTOcard VALUES(,G002Qian qi, cs, 6);20. INSERT INTOcard VALUESCUeei,Li Fen, auto, U);21. INSERT INTOcard VALUES(,U002,Bai
16、 La, art, U);22. INSERT INTOcard VALUES(F001Zhang Fa, pku F1);23. INSERT INTOcard VALUES(F002,Li Aigu, stu, 1F1);24.25.-插入数据-插入Borrow表数据26. INSERT INTOborrow VALUES(T001,b0001, 12022-01-10 12022-03-041);27. INSERT INTOborrow VALUES(17001,1b00021, 12022-05-10, 12022-08-01,);28. INSERT INTOborrow VALU
17、ES(T001,b0005, 2022-01-01, 12022-03-04);29. INSERT INTOborrow VALUES(T001,1b00101, 12022-01-01 2022-03-041);30. INSERT INTOborrow VALUES(T003,b0001, 12022-05-15 12022-08-04*);31. INSERT INTOborrow VALUES(*T003,b0002, 2022-03-15, 12022-04-04);32. INSERT INTOborrow VALUES(*T003,b0003, 2022-02-15, 1202
18、2-03-041);33. INSERT INTOborrow VALUES(,T003,b0004, 2021-02-15, 12021-03-04);34. INSERT INTOborrow VALUES(G002,b0005, 2022-05-05, 12022-07-04);35. INSERT INTOborrow VALUES(G002,b0007, ,2022-08-10, NULL);36. INSERT INTOborrow VALUES(G002,b0010, 2022-07-10, NULL);37. INSERT INTOborrow VALUES(U001,b000
19、9, 2022-02-02, 2022-03-09,);38. INSERT INTOborrow VALUES(U001,b0008, 2022-02-02, 12022-03-09,);39. INSERT INTOborrow VALUES(*U002,b0003, 2022-03-06, 12022-03-091);40. INSERT INTOborrow VALUES(U002,b0004, 2022-04-02, 2022-05-09,);41. INSERT INTOborrow VALUES(F001,1b00011, ,2022-08-12, 2022-08-15);42.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 广东工业大学 SQL 编程 报告
限制150内