当前位置: 首页 > news >正文

【MySQL】深圳大学数据库实验一

目录

一、实验目的

二、实验要求

三、实验设备

四、建议的实验步骤

4.1 使用SQL语句创建如上两张关系表

4.2 EXERCISES. 1 SIMPLE COMMANDS

4.3 EXERCISES 2 JOINS

4.4 EXERCISES 3 FUNCTIONS

4.5 EXERCISES 4 DATES

五、实验总结

5.1 数据库定义语言(DDL)

5.2 数据操作语言(DML)

5.3 数据查询语言(DQL)


一、实验目的

  1. 了解DBMS系统的功能、软件组成;
  2. 掌握利用SQL语句定义、操纵数据库的方法。

二、实验要求

  1. 在课外安装相关软件并浏览软件自带的帮助文件和功能菜单,了解DBMS的功能、结构;

  2. 创建一个有两个关系表的数据库;(建议采用MYSQL)

  3. 数据库、关系表定义;

  4. 学习定义关系表的约束(主键、外键、自定义);

  5. 了解SQL的数据定义功能;

  6. 了解SQL的操纵功能;

  7. 掌握典型的SQL语句的功能;

  8. 了解视图的概念;

三、实验设备

        计算机、数据库管理系统如MYSQL等软件。

四、建议的实验步骤

        使用SQL语句建立关系数据库模式及数据如下:(注:数据要自己输入)

4.1 使用SQL语句创建如上两张关系表

创建表格(CREATE TABLE):用于创建一个新表格并定义其结构。

CREATE TABLE table_name (column1 datatype [constraint],column2 datatype [constraint],...[table_constraints]
);

拓展: 

修改表格(ALTER TABLE)

ALTER TABLE table_nameADD column_name datatype [constraint],DROP column_name,MODIFY COLUMN column_name datatype [constraint],CHANGE COLUMN old_column_name new_column_name datatype [constraint];

删除表格(DROP TABLE)

DROP TABLE table_name;

重命名表格(RENAME TABLE)

RENAME TABLE old_table_name TO new_table_name;

创建和删除索引 (CREATE INDEX // DROP INDEX):

CREATE INDEX index_name ON table_name (column_name);DROP INDEX index_name ON table_name;

创建和删除视图(CREATE VIEW // DROP VIEW)

-- 创建视图
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;-- 删除视图
DROP VIEW view_name;

创建emp和dept表格 

create table dept2022150212
(DEPTNO int not null ,DNAME varchar(30) not null ,LOC varchar(30) not null ,PRIMARY KEY (DEPTNO)
);create table emp2022150212
(EMPNO int not null,ENAME varchar(30) not null,JOB varchar(30) not null,MGR int,HIREDATE varchar(30),SAL int,COMM int,DEPTNO int not null,primary key (EMPNO));

 插入数据 (INSERT INTO) :用于向表格中插入新记录。

 拓展:
更新数据 (UPDATE):

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

删除数据 (DELETE):

DELETE FROM table_name
WHERE condition;

 批量插入、更新、删除

-- 批量插入
INSERT INTO employees (name, salary, hire_date, manager_id)
VALUES ('Emily Davis', 6200.00, '2024-09-01', 4),('Michael Brown', 6700.00, '2024-08-20', 4);-- 批量更新
UPDATE employees
SET salary = salary * 1.05
WHERE hire_date < '2024-01-01';-- 批量删除
DELETE FROM employees
WHERE hire_date < '2024-01-01';

使用事务 :在执行 DML 操作时,特别是涉及多条记录的操作时,可以使用事务来确保数据的完整性。事务包括 START TRANSACTIONCOMMITROLLBACK 操作。

-- 开始事务
START TRANSACTION;-- 执行多个 DML 操作
UPDATE employees SET salary = salary * 1.10 WHERE department = 'Sales';
DELETE FROM employees WHERE hire_date < '2023-01-01';-- 提交事务
COMMIT;-- 如果出现错误,可以回滚事务
ROLLBACK;

插入数据

// 插入部门数据
insert into dept2022150212 (DEPTNO, DNAME, LOC) values (10, 'ACCOUNTING', 'LONDON');
insert into dept2022150212 (DEPTNO, DNAME, LOC) values (20, 'RESEARCH', 'PRESTON');
insert into dept2022150212 (DEPTNO, DNAME, LOC) values (30, 'SALES', 'LIVERPOOL');
insert into dept2022150212 (DEPTNO, DNAME, LOC) values (40, 'OPERATIONS', 'STAFFORD');
insert into dept2022150212 (DEPTNO, DNAME, LOC) values (50, 'MARKETING', 'LUTON');// 插入员工数据
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7369, 'SMITH', 'CLERK', 7902, '17-Dec-90', 13750, 0, 20);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7499, 'ALLEN', 'SALESMAN', 7698, '20-FEB-89', 19000, 6400, 30);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7521, 'WARD', 'SALESMAN', 7698, '22-FEB-93', 18500, 4250, 30);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7566, 'JONES', 'MANAGER', 7839, '02-APR-89', 26850, 0, 20);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7654, 'MARTIN', 'SALESMAN', 7698, '28-SEP-97', 15675, 3500, 30);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7698, 'BLAKE', 'MANAGER', 7839, '01-MAY-90', 24000, 0, 30);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7782, 'CLARK', 'MANAGER', 7839, '09-JUN-88', 27500, 0, 10);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7788, 'SCOTT', 'ANALYST', 7566, '19-APR-87', 19500, 0, 20);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7839, 'KING', 'PRESIDENT', 7902, '17-NOV-83', 82500, 0, 10);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7844, 'TURNER', 'SALESMAN', 7698, '08-SEP-92', 18500, 6250, 30);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7876, 'ADAMS', 'CLERK', 7788, '23-MAY-96', 11900, 0, 20);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7900, 'JAMES', 'CLERK', 7698, '03-DEC-95', 12500, 0, 30);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7902, 'FORD', 'ANALYST', 7566, '03-DEC-91', 21500, 0, 20);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (7934, 'MILLER', 'CLERK', 7782, '23-JAN-95', 13250, 0, 10);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (3258, 'GREEN', 'SALESMAN', 4422, '24-Jul-95', 18500, 2750, 50);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (4422, 'STEVENS', 'MANAGER', 7839, '14-Jan-94', 24750, 0, 50);
insert into emp2022150212 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
values (6548, 'BARNES', 'CLERK', 4422, '16-Jan-95', 11950, 0, 50);

4.2 EXERCISES. 1 SIMPLE COMMANDS

-- 1.List all information about the employees.
select * from emp2022150212;-- 2.List all information about the departments
select * from dept2022150212;-- 3.List only the following information from the EMP table ( Employee 	name, employee number, salary, department number)
select ENAME, EMPNO, SAl, DEPTNO  from emp2022150212;-- 4.List details of employees in departments 10 and 30.
select * from emp2022150212 where DEPTNO between 10 and 30;-- 5.List all the jobs in the EMP table eliminating duplicates.
select JOB from emp2022150212 group by JOB;-- 6.What are the names of the employees who earn less than £20,000?
select ENAME from emp2022150212 where SAL <= 20000;-- 7.What is the name, job title and employee number of the person in department 20 who earns more than £25000?
select ENAME, JOB, EMPNO from emp2022150212 where DEPTNO = 20 and SAL > 25000;-- 8.Find all employees whose job is either Clerk or Salesman.
select * from emp2022150212 where JOB = 'Clerk' or JOB = 'Salesman';-- 9.Find any Clerk who is not in department 10.
select * from emp2022150212 where DEPTNO != 10 and JOB = 'Clerk';-- 10.Find everyone whose job is Salesman and all the Analysts in department 20.
select * from emp2022150212 where JOB = 'Salesman' and  DEPTNO = 20;-- 11.Find all the employees who earn between £15,000 and £20,000. Show the employee name, department and salary.
select ENAME, DEPTNO, SAL from emp2022150212 where SAL between  15000 and 20000;-- 12.Find the name of the President.
select ENAME from emp2022150212 where JOb = 'President';-- 13.Find all the employees whose last names end with S
select * from emp2022150212 where ENAME like '%S';-- 14.List the employees whose names have TH or LL in them
Select * from emp2022150212 where ENAME like '%TH%' or '%LL%';-- 15.List only those employees who receive commission.
select * from emp2022150212 where COMM != 0;-- 16.Find the name, job, salary, hiredate, and department number of all employees by alphabetical order of name.
select ENAMe, JOB, SAL, HIREDATE, DEPTNO from emp2022150212 order by ENAME;-- 17.Find the name, job, salary, hiredate and department number of all employees in ascending order by their salaries.
select ENAME, JOB, SAL, HIREDATE, DEPTNO from emp2022150212 order by SAL asc ;-- 18.List all salesmen in descending order by commission divided by their salary.
select * from emp2022150212 where JOB = 'Salesman' order by (COMM / SAL) desc;-- 19.Order employees in department 30 who receive commision, in ascending order by commission
select * from emp2022150212 where DEPTNO = 30 and COMM != 0 order by COMM desc;-- 20.Find the names, jobs, salaries and commissions of all employees who do not have managers.
select ENAME, JOB, SAL, COMM from emp2022150212 where JOB != 'Managers';-- 21.Find all the salesmen in department 30 who have a salary greater than or equal to £18000.
select * from emp2022150212 where JOB = 'Salesman' and DEPTNO = 30 and SAL >= 18000;

4.3 EXERCISES 2 JOINS

JOIN 用于将两个或多个表格中的记录基于相关列连接在一起。JOIN 分为内连接(INNER JOIN)、左外连接(LEFT JOINLEFT OUTER JOIN)、右外连接(RIGHT JOINRIGHT OUTER JOIN)和全外连接(FULL JOINFULL OUTER JOIN)。

4.3.1 左外连接(LEFT JOINLEFT OUTER JOIN

左外连接返回左表中的所有记录以及右表中匹配的记录。如果右表中没有匹配的记录,结果集中会包含左表中的记录和右表中列的 NULL 值。

语法:

SELECT columns
FROM left_table
LEFT JOIN right_table
ON left_table.common_column = right_table.common_column;

4.3.2 右外连接 (RIGHT JOINRIGHT OUTER JOIN

右外连接返回右表中的所有记录以及左表中匹配的记录。如果左表中没有匹配的记录,结果集中会包含右表中的记录和左表中列的 NULL 值。

语法:

SELECT columns
FROM left_table
RIGHT JOIN right_table
ON left_table.common_column = right_table.common_column;

4.3.3  全外连接(FULL JOINFULL OUTER JOIN

全外连接返回左表和右表中的所有记录,匹配的记录会连接在一起。如果某一表中的记录在另一表中没有匹配项,则结果集中会包含该记录以及另一表中列的 NULL 值。注意,MySQL 并不直接支持 FULL OUTER JOIN,可以通过联合 LEFT JOINRIGHT JOIN 实现。

语法:

SELECT columns
FROM left_table
LEFT JOIN right_table
ON left_table.common_column = right_table.common_columnUNIONSELECT columns
FROM left_table
RIGHT JOIN right_table
ON left_table.common_column = right_table.common_column;

4.3.4 段小结

  • 左外连接(LEFT JOINLEFT OUTER JOIN:返回左表中的所有记录及右表中匹配的记录,如果没有匹配,则右表的列为 NULL
  • 右外连接(RIGHT JOINRIGHT OUTER JOIN:返回右表中的所有记录及左表中匹配的记录,如果没有匹配,则左表的列为 NULL
  • 全外连接(FULL JOINFULL OUTER JOIN:返回左表和右表中的所有记录,包括没有匹配的记录,MySQL 需要通过联合 LEFT JOINRIGHT JOIN 来实现。
-- 1.Find the name and salary of employees in Luton.
select e.ENAME, e.SAL
from emp2022150212 eleft join dept2022150212 d on e.DEPTNO = d.DEPTNO
where e.DEPTNO = d.DEPTNOand d.LOC = 'LUTON';-- 2.Join the DEPT table to the EMP table and show in department number order.
select *
from emp2022150212 eleft join dept2022150212 d on e.DEPTNO = d.DEPTNO
order by e.DEPTNO;-- 3.List the names of all salesmen who work in SALES
select e.ENAME
from emp2022150212 eleft join dept2022150212 d on e.DEPTNO = d.DEPTNO
where d.DNAME = 'SALES'and e.JOB = 'Salesman';-- 4.List all departments that do not have any employees.
select d.DNAME
from emp2022150212 eright join dept2022150212 d on e.DEPTNO = d.DEPTNO
group by d.DNAME
having count(e.DEPTNO) = 0;-- 5.For each employee whose salary exceeds his manager's salary, list the 	employee's name and salary and the manager's name and salary.
select e.ENAME, e.SAL, t.ENAME, t.SAL
from emp2022150212 eleft join emp2022150212 t on e.DEPTNO = t.DEPTNO
where e.SAL > t.SALand t.JOB = 'Manager'and e.JOB != 'Manager';-- 6.List the employees who have BLAKE as their manager.
select e.DEPTNO, e.ENAME, t.DEPTNO, t.ENAME
from emp2022150212 eright join emp2022150212 t on e.DEPTNO = t.DEPTNO
where t.ENAME = 'BLAKE'and e.ENAME != 'BLAKE';

4.4 EXERCISES 3 FUNCTIONS

在 MySQL 中,聚合函数用于对一组值执行计算,通常用于生成汇总数据。这些函数可以在 SQL 查询中帮助你统计、计算或总结数据。以下是 MySQL 中常见的聚合函数及其用法:

1. COUNT()

计算行数或特定列中的非空值的数量。

SELECT COUNT(column_name) FROM table_name;

2. SUM()

计算一列数值的总和。

SELECT SUM(column_name) FROM table_name;

3. AVG()

计算一列数值的平均值。

SELECT AVG(column_name) FROM table_name;

4. MIN()

获取一列数值中的最小值。

SELECT MIN(column_name) FROM table_name;

5. MAX()

获取一列数值中的最大值。

SELECT MAX(column_name) FROM table_name;

练习: 

-- 1.Find how many employees have a title of manager without listing them.
select count(*)
from emp2022150212 e
where e.JOB = 'Manager';-- 2.Compute the average annual salary plus commission for all salesmen
select avg(e.SAL + e.COMM)
from emp2022150212 e
where e.JOB = 'Salesman';-- 3.Find the highest and lowest salaries and the difference between them (single SELECT statement)
select max(e.SAL), min(e.SAL), max(e.SAL) - min(e.SAL)
from emp2022150212 e;-- 4.Find the number of characters in the longest department name
select max(LENGTH(d.DNAME))
from dept2022150212 d;-- 5.Count the number of people in department 30 who receive a salary and the number of people who receive a commission (single statement).
select count(e.SAL), count(e.COMM)
from emp2022150212 e
where e.DEPTNO = 30;-- 6.List the average commission of employees who receive a commission, and the average commission of all employees (assume employees who do not receive a commission attract zero commission)
select avg(e.COMM), avg(t.COMM)
from emp2022150212 e,emp2022150212 t
where e.COMM != 0;-- 7.List the average salary of employees that receive a salary, the average commission of employees that receive a commission, the average salary 	plus commission of only those employees that receive a 	commission and the average salary plus commission of all employees including  those that do not receive a commission. (single statement)
select avg(e.SAL), avg(t.COMM), avg(g.SAL + g.COMM), avg(h.SAL + h.COMM)
from emp2022150212 e,emp2022150212 t,emp2022150212 g,emp2022150212 h
where e.SAL != 0and t.COMM != 0and g.COMM != 0;-- 8.Compute the daily and hourly salary for employees in department 30, round to the nearest penny. Assume there are 22 working days in a month and 8 working hours in a day.
select e.ENAME, round(e.SAL / 22) 月薪, round(e.SAl / 22 / 8) 日薪
from emp2022150212 e
where e.DEPTNO = 30;-- 9.Issue the same query as the previous one except that this time truncate (TRUNC) to the nearest penny rather than round.
select e.ENAME, floor(e.SAL / 22) 月薪, floor(e.SAl / 22 / 8) 日薪
from emp2022150212 e
where e.DEPTNO = 30;

小结 :

4.5 EXERCISES 4 DATES

4.5.1 日期的各种方法

-- 获取当前日期 : CURDATE() 或 CURRENT_DATE() 
-- => 返回当前日期,不包含时间部分。
SELECT CURDATE();
-- 或
SELECT CURRENT_DATE();-- ============================================ ---- 获取当前时间戳 : NOW() 
-- => 返回当前的日期和时间。
SELECT NOW();-- ============================================ ---- 日期计算和操作
-- DATE_ADD():向日期添加指定的时间间隔。
-- DATE_SUB():从日期减去指定的时间间隔。
-- DATEDIFF():计算两个日期之间的天数差。
-- DATE_FORMAT():格式化日期为特定的字符串格式。
-- ===实例=== --
-- 向日期添加 10 天
SELECT DATE_ADD('2024-09-05', INTERVAL 10 DAY);-- 从日期中减去 1 个月
SELECT DATE_SUB('2024-09-05', INTERVAL 1 MONTH);-- 计算两个日期之间的天数
SELECT DATEDIFF('2024-09-15', '2024-09-05');-- 格式化日期
SELECT DATE_FORMAT('2024-09-05', '%Y年%m月%d日');-- ============================================ ---- 提取日期部分
-- YEAR():提取年份。
-- MONTH():提取月份。
-- DAY():提取日期中的日。
-- WEEKDAY():提取星期几(0 = 周一, 6 = 周日)。
-- ===实例=== --
-- 提取年份
SELECT YEAR('2024-09-05');-- 提取月份
SELECT MONTH('2024-09-05');-- 提取日期
SELECT DAY('2024-09-05');-- 提取星期几
SELECT WEEKDAY('2024-09-05');-- ============================================ ---- 日期处理函数
-- LAST_DAY():返回指定日期所在月的最后一天。
-- STR_TO_DATE():将字符串转换为日期。
-- DATE():提取日期部分(无时间部分)。
-- ===实例=== --
-- 返回指定日期所在月的最后一天
SELECT LAST_DAY('2024-09-05');-- 将字符串转换为日期
SELECT STR_TO_DATE('05-09-2024', '%d-%m-%Y');-- 提取日期部分
SELECT DATE(NOW());

练习: 

-- 1.Select the name, job, and date of hire of the employees in department 20. (Format the HIREDATE column to MM/DD/YY)
select ENAME, JOB, HIREDATE
from emp2022150212
where DEPTNO = 20;-- 2.Then format the HIREDATE column into DoW (day of the week), Day (day of the month), MONTH (name of the month) and YYYY(year)
SELECT HIREDATE,DAYOFWEEK(STR_TO_DATE(HIREDATE, '%d-%b-%y')) AS week,DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y'))       AS day,MONTH(STR_TO_DATE(HIREDATE, '%d-%b-%y'))     AS month,YEAR(STR_TO_DATE(HIREDATE, '%d-%b-%y'))      AS year
FROM emp2022150212;-- 3.3Which employees were hired in April?
select *
from emp2022150212
where MONTH(STR_TO_DATE(HIREDATE, '%d-%b-%y')) = 4;-- 4.Which employees were hired on a Tuesday?
select *
from emp2022150212
where DAYOFWEEK(STR_TO_DATE(HIREDATE, '%d-%b-%y')) = 2;-- 5.Are there any employees who have worked more than 30 years for the company?
select *
from emp2022150212
where YEAR(CURDATE()) - YEAR(STR_TO_DATE(HIREDATE, '%d-%b-%y')) > 30;-- 6.Show the weekday of the first day of the month in which each employee was hired. (plus their names)
select ENAME,DAYNAME(STR_TO_DATE(CONCAT('01-', DATE_FORMAT(STR_TO_DATE(HIREDATE, '%d-%b-%y'), '%b-%y')),'%d-%b-%y')) AS first_day_weekday
from emp2022150212;-- 7.Show details of employee hiredates and the date of their first payday. (Paydays occur on the last Friday of each month) (plus their names)
select ENAME,-- 如果入职日期在当前月的最后一个星期五之后,计算下下一个月的最后一个星期五CASEWHEN STR_TO_DATE(HIREDATE, '%d-%b-%y') > DATE_SUB(LAST_DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y')), INTERVAL(WEEKDAY(LAST_DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y'))) + 3) % 7 DAY) THEN-- 计算下一个月的最后一个星期五DATE_SUB(LAST_DAY(STR_TO_DATE(CONCAT(DATE_FORMAT(STR_TO_DATE(HIREDATE, '%d-%b-%y'), '%y-%m'), '-01'),'%Y-%m-%d') + INTERVAL 1 MONTH),INTERVAL (WEEKDAY(LAST_DAY(STR_TO_DATE(CONCAT(DATE_FORMAT(STR_TO_DATE(HIREDATE, '%d-%b-%y'), '%Y-%m'), '-01'), '%Y-%m-%d') +INTERVAL 1 MONTH)) + 3) % 7 DAY)ELSE-- 计算当前月的最后一个星期五DATE_SUB(LAST_DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y')), INTERVAL(WEEKDAY(LAST_DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y'))) + 3) % 7 DAY)END AS first_payday
from emp2022150212;-- 8.Refine your answer to 7 such that it works even if an employee is hired after the last Friday of the month (cf Martin)
select ENAME,HIREDATE,DATE_SUB(LAST_DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y')), INTERVAL(WEEKDAY(LAST_DAY(STR_TO_DATE(HIREDATE, '%d-%b-%y'))) + 3) % 7 DAY)
from emp2022150212;

五、实验总结

5.1 数据库定义语言(DDL)

DDL 用于定义和管理数据库的结构,包括创建、修改和删除表格、索引、视图等对象。常见的 DDL 操作包括:

  • CREATE TABLE:创建新的表格
  • ALTER TABLE:修改现有表格的结构
  • DROP TABLE:删除表格及其数据
  • CREATE INDEX:创建索引
  • DROP INDEX:删除索引
  • CREATE VIEW:创建视图
  • DROP VIEW:删除视图

示例:

-- 创建表格
CREATE TABLE employees (id INT AUTO_INCREMENT PRIMARY KEY,name VARCHAR(100) NOT NULL,salary DECIMAL(10, 2) NOT NULL,manager_id INT,FOREIGN KEY (manager_id) REFERENCES employees(id)
);-- 修改表格
ALTER TABLE employees ADD COLUMN department VARCHAR(50);-- 删除表格
DROP TABLE employees;

5.2 数据操作语言(DML)

DML 用于操作表格中的数据,包括插入、更新和删除记录。常见的 DML 操作包括:

  • INSERT INTO:插入新记录
  • UPDATE:更新现有记录
  • DELETE:删除记录
-- 插入数据
INSERT INTO employees (name, salary, manager_id) VALUES ('John Doe', 5000.00, 2);-- 更新数据
UPDATE employees SET salary = 5500.00 WHERE name = 'John Doe';-- 删除数据
DELETE FROM employees WHERE name = 'John Doe';

5.3 数据查询语言(DQL)

DQL 用于查询数据库中的数据。主要的 DQL 操作是:

  • SELECT:从表格中检索数据

相关文章:

【MySQL】深圳大学数据库实验一

目录 一、实验目的 二、实验要求 三、实验设备 四、建议的实验步骤 4.1 使用SQL语句创建如上两张关系表 4.2 EXERCISES. 1 SIMPLE COMMANDS 4.3 EXERCISES 2 JOINS 4.4 EXERCISES 3 FUNCTIONS 4.5 EXERCISES 4 DATES 五、实验总结 5.1 数据库定义语言&#xff08;DDL…...

接口测试 —— 如何设计高效的测试用例!

摘要&#xff1a; 随着互联网应用的日益复杂化&#xff0c;接口测试已成为保证软件质量不可或缺的一部分。本文将探讨如何有效地设计接口测试用例&#xff0c;并提供实用的建议和示例。 一、引言 接口测试&#xff08;API测试&#xff09;是确保系统各部分之间交互正确性的关键…...

linux top命令介绍以及使用

文章目录 介绍 top 命令1. top 的基本功能2. 如何启动 top3. top 的输出解释系统概况任务和 CPU 使用情况内存和交换空间进程信息 4. 常用操作 总结查看逻辑CPU的个数查看系统运行时间 介绍 top 命令 top 是一个在类 Unix 系统中广泛使用的命令行工具&#xff0c;用于实时显示…...

必备资源!精选大模型领域100篇必读论文,赶紧加入收藏夹!

本文主要为当前大模型领域热门研究方向&#xff08;如文生图、文生视频、文生音乐等&#xff09;的热门论文。希望能够为大家提供较为全面的大模型最新研究进展。当然&#xff0c;目前还无法涵盖所有热门论文以及研究方向&#xff0c;望请见谅。 以下&#xff0c;为2024年2月份…...

基于STM32设计的防盗书包(华为云IOT)(216)

文章目录 一、前言1.1 项目介绍【1】开发背景【2】项目实现的功能【3】项目硬件模块组成1.2 设计思路【1】整体设计思路【2】整体构架【3】上位机开发思路1.3 项目开发背景【1】选题的意义【2】可行性分析【3】参考文献【4】摘要【5】项目背景1.4 开发工具的选择【1】设备端开发…...

2024高教社杯全国大学生数学建模竞赛C题原创python代码

2024高教社杯全国大学生数学建模竞赛C题原创python代码 C题题目&#xff1a;农作物的种植策略 思路可以参考我主页之前的文章 以下均为python代码&#xff0c;推荐用anaconda中的notebook当作编译环境 from gurobipy import Model import pandas as pd import gurobipy as g…...

Java基础 - 14 - Java高级技术

一.单元测试 就是针对最小的功能单元&#xff08;方法&#xff09;&#xff0c;编写测试代码对其进行正确性测试 1.1 Junit单元测试框架 可以用来对方法进行测试&#xff0c;它是第三方公司开源出来的&#xff08;很多开发工具已经集成了Junit框架&#xff0c;如IDEA&#xff…...

glsl着色器学习(六)

准备工作已经做完&#xff0c;下面开始渲染 gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);gl.clearColor(0.5, 0.7, 1.0, 1.0); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);gl.enable(gl.DEPTH_TEST); gl.enable(gl.CULL_FACE);设置视口 gl.viewport(0,…...

毒枸杞事件启示录:EasyCVR视频AI智能监管方案如何重塑食品卫生安全防线

一、方案背景 近年来&#xff0c;食品安全问题频发&#xff0c;引发了社会各界的广泛关注。其中&#xff0c;毒枸杞事件尤为引人关注。新闻报道&#xff0c;在青海格尔木、甘肃靖远等地&#xff0c;部分商户为了提升枸杞的品相&#xff0c;违规使用焦亚硫酸钠和工业硫磺进行“…...

git进阶·团队开发的时候为何要创建临时分支来修复bug

若在团队开发中&#xff0c;突然遇到一个功能性bug&#xff0c;你会怎么使用git来管理分支呢&#xff1f; 在近些年来&#xff0c;团队工作的经验中&#xff0c;我总结出来的是&#xff0c;最好是先创建一个临时分支来修复bug&#xff0c;修复好后&#xff0c;再合并到主分支或…...

Unity 性能优化工具收集

本文地址&#xff1a;https://blog.csdn.net/t163361/article/details/141809415 Unity原始工具 UPR 官方 UPR UPR桌面端解决方案&#xff0c;减轻测试设备性能压力&#xff0c;使测试过程更加顺畅。提供CLI用于自动化测试系统对接。 PerformanceBenchmarkReporter Unity 性…...

linux下的Socket网络编程教程

套接字概念 Socket本身有“插座”的意思&#xff0c;在Linux环境下&#xff0c;用于表示进程间网络通信的特殊文件类型。本质为内核借助缓冲区形成的伪文件。与管道类似的&#xff0c;Linux系统将其封装成文件的目的是为了统一接口&#xff0c;使得读写套接字和读写文件的操作…...

华为人工智能重要服务总结

一&#xff0c;视觉智能服务 一&#xff0c;图像识别服务 1.媒资图像标签服务 媒资素材管理&#xff0c;内容推荐广告营销等 2.图像描述服务 融合计算机视觉&#xff0c;自然语言处理和多模态技术&#xff0c;对输入图像进行画面内容描述 3.主体识别服务 像主体识别能检测出…...

涉嫌欺诈者利用机器人通过播放AI创作的音乐赚取1000万美元版税

北卡罗莱纳州的一名男子因涉嫌上传数十万首由AI生成的歌曲到流媒体服务平台&#xff0c;并使用机器人播放数十亿次而面临诈骗指控。自2017年以来&#xff0c;Michael Smith据称通过这一方式获得了超过1000万美元的版税收入。更多详情 现年52岁的Smith于周三被逮捕。同一天公布…...

k8s helm

k8s Helm 是Kubernetes的包管理工具&#xff0c;类似于Linux系统中常用的apt、yum等包管理工具。Helm通过定义、安装和升级Kubernetes应用程序来简化Kubernetes应用部署的复杂性。以下是对k8s Helm的详细解析&#xff1a; 一、Helm的基本概念 Chart&#xff1a;Chart是Helm的…...

KMP 详解

KMP数组存的是什么 对于一个字符串 b,下标从1开始。 则kmp[i]表示 以i结尾的连续子串 s的前缀的最大值&#xff08;等价于前缀最大结尾处&#xff09; 如何求KMP 假设 i 以前的KMP都被求出来了。 j 表示上一个字符可以成功匹配的长度&#xff08;等价于下标&#xff09; …...

go语言并发编程-超详细mutex解析

文章目录 1 go语言并发编程学习-mutex1.1 学习过程1.2 如何解决资源并发访问的问题&#xff1f;【基本用法】1.2.1 并发访问带来的问题1.2.1.1 导致问题的原因 1.2.2 race detector检查data race1.2.3 mutex的基本实现机制以及使用方法1.2.3.1 具体使用-11.2.3.1 具体使用-2 1 …...

VirtualBox Debian 自动安装脚本

概览 相较于原脚本&#xff08;安装目录/UnattendedTemplates/debian_pressed.cfg&#xff09;更新如下内容&#xff1a; 配置清华镜像源配置仅主机网卡&#xff08;后续只需添加仅主机网卡即可&#xff09;配置Root用户远程登录配置用户sudo组 脚本 debian_pressed.cfg ##…...

最好的开放式耳机?五款红榜开放式耳机推荐!

面对众多的开放式耳机选项&#xff0c;消费者可能会感到难以抉择。买耳机不一定要买最贵最好的&#xff0c;但是一定要选最适合自己的&#xff0c;为了使选择过程更加容易&#xff0c;我提供了一些建议&#xff0c;推荐了几款既适合日常使用又佩戴舒适的热门开放式耳机。 开放式…...

线性代数之线性方程组

目录 线性方程组 1. 解的个数 齐次线性方程组&#xff1a; 非齐次线性方程组&#xff1a; 2. 齐次线性方程组的解 3. 非齐次线性方程组的解 4. 使用 Python 和 NumPy 求解线性方程组 示例代码 齐次线性方程组 非齐次线性方程组 示例结果 齐次线性方程组 非齐次线性…...

Qt/C++开发监控GB28181系统/取流协议/同时支持udp/tcp被动/tcp主动

一、前言说明 在2011版本的gb28181协议中&#xff0c;拉取视频流只要求udp方式&#xff0c;从2016开始要求新增支持tcp被动和tcp主动两种方式&#xff0c;udp理论上会丢包的&#xff0c;所以实际使用过程可能会出现画面花屏的情况&#xff0c;而tcp肯定不丢包&#xff0c;起码…...

【SQL学习笔记1】增删改查+多表连接全解析(内附SQL免费在线练习工具)

可以使用Sqliteviz这个网站免费编写sql语句&#xff0c;它能够让用户直接在浏览器内练习SQL的语法&#xff0c;不需要安装任何软件。 链接如下&#xff1a; sqliteviz 注意&#xff1a; 在转写SQL语法时&#xff0c;关键字之间有一个特定的顺序&#xff0c;这个顺序会影响到…...

论文浅尝 | 基于判别指令微调生成式大语言模型的知识图谱补全方法(ISWC2024)

笔记整理&#xff1a;刘治强&#xff0c;浙江大学硕士生&#xff0c;研究方向为知识图谱表示学习&#xff0c;大语言模型 论文链接&#xff1a;http://arxiv.org/abs/2407.16127 发表会议&#xff1a;ISWC 2024 1. 动机 传统的知识图谱补全&#xff08;KGC&#xff09;模型通过…...

python执行测试用例,allure报乱码且未成功生成报告

allure执行测试用例时显示乱码&#xff1a;‘allure’ &#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;ڲ&#xfffd;&#xfffd;&#xfffd;&#xfffd;ⲿ&#xfffd;&#xfffd;&#xfffd;Ҳ&#xfffd;&#xfffd;&#xfffd;ǿ&#xfffd;&am…...

PAN/FPN

import torch import torch.nn as nn import torch.nn.functional as F import mathclass LowResQueryHighResKVAttention(nn.Module):"""方案 1: 低分辨率特征 (Query) 查询高分辨率特征 (Key, Value).输出分辨率与低分辨率输入相同。"""def __…...

RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)

RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发&#xff0c;后来由Pivotal Software Inc.&#xff08;现为VMware子公司&#xff09;接管。RabbitMQ 是一个开源的消息代理和队列服务器&#xff0c;用 Erlang 语言编写。广泛应用于各种分布…...

【C++】纯虚函数类外可以写实现吗?

1. 答案 先说答案&#xff0c;可以。 2.代码测试 .h头文件 #include <iostream> #include <string>// 抽象基类 class AbstractBase { public:AbstractBase() default;virtual ~AbstractBase() default; // 默认析构函数public:virtual int PureVirtualFunct…...

医疗AI模型可解释性编程研究:基于SHAP、LIME与Anchor

1 医疗树模型与可解释人工智能基础 医疗领域的人工智能应用正迅速从理论研究转向临床实践,在这一过程中,模型可解释性已成为确保AI系统被医疗专业人员接受和信任的关键因素。基于树模型的集成算法(如RandomForest、XGBoost、LightGBM)因其卓越的预测性能和相对良好的解释性…...

深入理解 React 样式方案

React 的样式方案较多,在应用开发初期,开发者需要根据项目业务具体情况选择对应样式方案。React 样式方案主要有: 1. 内联样式 2. module css 3. css in js 4. tailwind css 这些方案中,均有各自的优势和缺点。 1. 方案优劣势 1. 内联样式: 简单直观,适合动态样式和…...

Linux操作系统共享Windows操作系统的文件

目录 一、共享文件 二、挂载 一、共享文件 点击虚拟机选项-设置 点击选项&#xff0c;设置文件夹共享为总是启用&#xff0c;点击添加&#xff0c;可添加需要共享的文件夹 查询是否共享成功 ls /mnt/hgfs 如果显示Download&#xff08;这是我共享的文件夹&#xff09;&…...