1. Experimental purpose
(1) Learn to use SQL statements to insert, modify and delete data in the database
(2) Master the insert, update, and delete commands to implement update operations such as inserting, modifying, and deleting table data.
2. Experimental tasks
Create a database, create the Employees table, Departments table, and Salary table, and add sample data of each table to the tables. As shown below.
Create database YGGL
Create the Employees table, Departments table and Salary table.
Insert records into three tables, use insert into and replace into, and understand the difference between the two.
Use SQL statements to modify table data
Use SQL commands to modify the Salary table and change the employee income numbered 020010 to 2890.
Increase the income of all employees by 100.
Add a column "Telephone" to the Employees table.
Use the SQL command to delete employee information numbered 010008 in Employees.
Use the TRANCATE TABLE statement to delete rows in the Salary table.
3. Preview content
Basic operations of data insertion, modification and deletion
Data insertion (INSERT): allows new data to be inserted into the table. The basic structure is `INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);`.
Data modification (UPDATE): allows updating existing data in the table, the basic structure is `UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;`.
Data deletion (DELETE): allows deletion of data in the table. The basic structure is `DELETE FROM table_name WHERE condition;`.
4. Experimental data and result analysis
Create database, create table
Insert question requirement information into the table
Modify table Salary
Add a column of phone numbers to the Employees table
Delete employee information numbered 010008 in Employees
Use the truncate table statement to delete all rows in the Salary table
5. Discussion of issues
Question 1: How to insert new data into the database table? Please give an example.
Answer 1: Use the INSERT INTO statement, such as `INSERT INTO students (name, age) VALUES ('John Doe', 25);`.
Question 2: How to modify the data in the database table? Please give an example.
Answer 2: Use UPDATE statement, for example `UPDATE students SET age = 26 WHERE name = 'John Doe';`.
Question 3: What precautions are taken for data deletion operations in the database to avoid accidentally deleting important data?
Answer 3: One preventive measure is to confirm that the WHERE clause accurately specifies the rows to be deleted before performing a DELETE operation. In addition, the database can be backed up regularly to prevent the impact of accidental deletion.