Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SQL 练习笔记

SQL 联表查询、事务、索引优化的学习笔记。

内容

联表查询

-- INNER JOIN 示例
SELECT u.name, b.book_name, br.borrow_date
FROM users u
JOIN borrow_records br ON u.id = br.user_id
JOIN books b ON br.book_id = b.id
WHERE br.status = 'borrowing';

事务

START TRANSACTION;
UPDATE borrow_records SET status = 'returned' WHERE id = 1;
UPDATE users SET fine = fine + 5 WHERE id = 1;
COMMIT;

索引优化

  • 为经常 WHERE 和 JOIN 的字段加索引
  • 避免在索引列上使用函数
  • EXPLAIN 分析执行计划

说明

自学 SQL 的练习记录,基于 MySQL。

About

SQL 练习:联表查询、事务、索引优化笔记

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors