mysql "Database and Table Operations"

Experiment content:
1. Experiment topic
Create an employee management database for enterprise management. The database is named YGGL, which contains employee information, department information, and employee salary information. The database YGGL contains the following three tables:
(1) Employees: employee information table
(2) Departments: department information table
(3) Salary: employee salary table
Insert picture description here

Insert picture description here
1. Use the command line to create the database YGGL.
(1) Open the MySQL command line client, enter the administrator password to log in, and use the CREATE statement to create the YGGL database.
CREATE DATABASE yggl;
(2) When the YGGL database exists, use the CREAT DATEBASE statement to create a new database YGGL, check the error message, and then try to add the IF NOT EXISTS keyword to create YGGL to see what changes.
CREATE DATABASE IF NOT EXISTS yggl;
(3) The experiment uses the command method to create the database YGGL1, the database character set is required to be utf8, and the proofreading rule is utf8_general_ci.
CREATE DATABASE IF NOT EXISTS yggl DEFAULT CHARSET=utf8;

2. Use SQL statements to modify, view, and delete tables and databases.
Use the command line to modify the table Salary name to Sal
alter table Salary rename to Sal;

Use the command line to modify the address column name in the table Emloyees to addr.
ALTER TABLE employees CHANGE address addr VARCHAR(20);

Use the command line to modify the data type of the modified column addr in the table Emloyees to char(20)
alter table employees modify addr char(20);

Use the command line to adjust the position of the sex column in the table Emloyees to the next position of the name column
alter table employees modify sex char(2) after name;

Use the command line to add a nation (ethnic) field to the Emloyees
table alter table Employees add nation char comment'ethnic ';

Use the command line to delete the nation (ethnic) field from the Emloyees
table alter table Employees drop nation;

Guess you like

Origin blog.csdn.net/ziyue13/article/details/112067952
Recommended