Dameng database experiment 1: DBMS operation, data definition and data update

Experiment 1 DBMS operation, data definition and data update

1. The purpose of the experiment:

1. Familiar with DBMS experimental environment;
2. 2. Familiar with the method of operating the database in SQL language, and judge the correctness of the result of SQL statement operation;
2. 3. Master the basic operations of graphical interactive tools, and learn to create and manage databases and tables;
4. Understand and master the SQL language: Be able to use create/alter/drop statements proficiently to create, modify and delete databases and basic tables; be able to use insert/update statements.
5. Complete the definition of the sample database, including the definition of the database, table creation, modification, deletion, and update.

2. Experimental requirements:

1. Familiar with the structure of the system database
2 . Understand and master the syntax of create, alter, drop, insert statements, especially the specific meaning and usage of various parameters; use SQL statements to create, modify and delete databases and basic tables. Learn how to debug common syntax errors in SQL statements.
3. Familiarize yourself with the contents of the sample database.

3. Key points and difficulties of the experiment:

The focus of the experiment is to create a database, basic tables, and perform basic data update operations.
Experimental difficulties: the use and understanding of Create, Alter, Insert, and Update statements.

4. Experiment content:

1. Configuration and use of database management tools

1.1. Installation and configuration of DBMS;

1.2. Open and close DBMS;

1.3. Use of command line and graphical tools.

2. Database creation and management

2.1. Create a new database named "TmptDB", view the database information, configure, rename and delete the database;

2.2. Create a new database "StudentDB".

3. Data definition and update

3.1. Create three data tables in studentDB

3.2. Adding records to the table

(1) STUDENT (student information form)
SNO (student number) SNAME (name) SEX (gender) SAGE (age) SDEPT (department)
95001 Li Yongnan 20 CS
95002 Liu Chennv 19 IS
95003 Wang Mingnv 18 MA
95004 Zhang Linan 19 IS
95005 Li Mingnan 22 CS
95006 Zhang Xiaomei Girl 23 IS
95007 Feng Xiaowen Girl 20 MA
Note: If Chinese is not accepted in SQL, you can change the relevant attribute values ​​to corresponding English. Be careful to use English punctuation in SQL code.
(2) COURSE (course schedule)
CNO (course number) CNAME (course name) CPNO (previous course) CCREDIT (credits)
1 Database 5 4
2 Mathematics 2
3 Information System 1 4
4 Operating System 6 3
5 Data Structure_EN 7 4
6 Data Processing 2
7 PASCAL Language 6 4
(3) SC (Elective Form)
SNO (Student Number) CNO (Course Number) Grade (Grade)
95001 1 92
95001 2 85
95001 3 88
95002 2 90
95002 3 80
95003 1 78
95003 2 80
95004 1 90
95004 4 60
95005 1 80
95005 3 89
95006 3 80
95007 4 65

3.3. View and modify table definitions

3.4. Data update and deletion

4. Comprehensive training

Through experiments, understand the characteristics of relational tables, and integrate relational algebra theory and SQL.

5. Experimental steps and results:

Description: For each part of the experimental content, please describe the experimental process and match the screenshots of the experimental results

1. Configuration and use of database management tools

1.1 DBMS installation and configuration

//Briefly describe the DBMS installation and configuration process, with screenshots of important steps

insert image description here

1.2 Turn on and off DBMS

/ / Briefly describe the method of operating the DBMS

insert image description here

1.3 Use of command line and graphical tools

//summarize the main points of using command line and graphical tools, which can be matched with screenshots
insert image description here

2. Database creation and management

// Combine the screenshots to illustrate the process and results

insert image description here

3. Data definition and update

3.1 Table Creation

(1) STUDENT
//Give a screenshot of the SQL statement, and briefly describe the content of each relationship; explain the settings of primary keys, foreign keys and corresponding constraints

RENAME TABLE `studentdb`.`sheet1$` TO `studentdb`.`student`;

(2)COURSE

RENAME TABLE `studentdb`.`sheet2$` TO `studentdb`.`course`; 

(3)SC

RENAME TABLE `studentdb`.`sheet3$` TO `studentdb`.`sc`; 

3.2 Adding records to the table

//Please give screenshots (SQL examples) to show the method of adding complete records and adding some non-empty records, and explain the difference between the two

ALTER TABLE `studentdb`.`student` CHANGE `SNO` `SNO` DOUBLE NOT NULL, ADD PRIMARY KEY (`SNO`); 

3.3 Viewing and Modifying Table Definitions

//View and modify the definition of the table through the operation of commands and graphical tools respectively, and explain the process and results in combination with screenshots. Complete the following tasks and explain the operation commands and their results with screenshots.
(1) Create a basic table in the way of SQL language:

tmp(aa char(2),bb int, cc varchar(10))CREATE TABLE `studentdb`.`temp`( `aa` CHAR(2), `bb` INT, `cc` VARCHAR(10) ); 

(2) Modify the tmp table, add 2 fields, dept char(30), demo char(10), and change the attribute of bb to smallint;

 ALTER TABLE `studentdb`.`temp` CHANGE `bb` `bb` SMALLINT(11) NULL, ADD COLUMN `dept` CHAR(30) NULL AFTER `cc`, ADD COLUMN `demo` CHAR(10) NULL AFTER `dept`;

(3) Delete a column of demo in the tmp table;

 ALTER TABLE `studentdb`.`temp` DROP COLUMN `demo`; 

(4) Add 10 records to tmp.

INSERT INTO `studentdb`.`temp` (`aa`, `bb`, `cc`, `dept`) VALUES ('1', '1', '2', '1'); 

3.4 Data update and deletion

//Complete the following tasks, and illustrate the process and results with the screenshots.
(1) Unconditionally update the value corresponding to an attribute in tmp;

UPDATE `studentdb`.`temp` SET `dept` = '4' WHERE `aa` = '9' AND `bb` = '1' AND `cc` = '5' AND `dept` IS NULL; 

(2) Unconditionally delete the data in tmp;

DELETE FROM `studentdb`.`temp` WHERE `aa` = '10' AND `bb` = '1' AND `cc` = '5' AND `dept` IS NULL; 

(3) delete table temp;

DROP TABLE `studentdb`.`temp`; 

(4) Modify the credits of "Database" in the Course table to 5.

UPDATE `studentdb`.`course` SET `CCREDIT` = '5' WHERE `CNO` = '1' AND `CNAME` = '数据库' AND `CPNO` = '5' AND `CCREDIT` = '4'; 

(5) All grades with course number 1 in SC will be deducted by 5 points.

UPDATE sc SET Grade = Grade-5 WHERE `sc`.`CNO`=1
SELECT * FROM sc WHERE `sc`.`CNO`=1

4. Comprehensive training

(1) Insert a new record into Student, where the student number is "95003". Did the insert operation succeed? Please explain the reasons based on the execution results.
Answer: It cannot be inserted, because the student ID is the primary key, and the primary key is unique, and the student ID is 95003.

(2) Delete the course whose course number is 1 in Course. Did the delete operation succeed? Please explain the reasons based on the execution results.
can delete

(3) Modify the course number of "PASCAL language" in Course to 8. Can it be executed successfully? Continue to modify the course number of "PASCAL language" in the course to 1. Can it be executed successfully? Please explain the reasons based on the execution results.

can be modified

(4) Execute the following statement, check the result, and understand the function of the statement based on the result. Also discuss which relational algebra operators can be used to obtain similar results and why?
Statement 1:Select * from student;

Statement 2:Select * from student, course;

Statement 3:select * from student where sage = 19;

Statement 4:select sno, sname from student;

Guess you like

Origin blog.csdn.net/david2000999/article/details/122504567