创建数据库YGGL、test和三张数据表的语句 2、按实训要求的其他语句
时间: 2023-05-27 20:07:37 浏览: 118
1. 创建数据库YGGL和test:
CREATE DATABASE YGGL;
CREATE DATABASE test;
2. 创建三张数据表:
CREATE TABLE employee (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT,
department VARCHAR(50)
);
CREATE TABLE department (
id INT PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE salary (
id INT PRIMARY KEY,
employee_id INT,
salary INT,
month VARCHAR(10),
FOREIGN KEY (employee_id) REFERENCES employee(id)
);
3. 其他语句:
- 插入数据:
INSERT INTO employee (id, name, age, department)
VALUES (1, '张三', 25, '销售部');
INSERT INTO department (id, name)
VALUES (1, '销售部');
INSERT INTO salary (id, employee_id, salary, month)
VALUES (1, 1, 5000, '2021-01');
- 查询数据:
SELECT * FROM employee;
SELECT * FROM department;
SELECT * FROM salary;
- 更新数据:
UPDATE employee SET age = 26 WHERE id = 1;
UPDATE salary SET salary = 5500 WHERE id = 1;
- 删除数据:
DELETE FROM employee WHERE id = 1;
DELETE FROM department WHERE id = 1;
DELETE FROM salary WHERE id = 1;
阅读全文