当前位置:网站首页>SQL数据库→约束→设计→多表查询→事务
SQL数据库→约束→设计→多表查询→事务
2022-07-27 05:01:00 【new一个对象_】
约束
1.约束的概念
约束是作用于表中列上的规则,用于限制加入表的数据
约束的存在保证了数据库中元素的正确性
2.约束的分类
外键约束(物理连接)
数据库设计
数据库设计什么?
◆有哪些表
◆表里有哪些字段
◆表和表之间是什么关系
表关系有哪几种?
注:ER图(Entity Relationship)
eg:(论坛系统ER图)
表关系
*一对一
*如:用户和用户详情
*一对一关系多用于表拆分,将一个实体中经常使用的字段放在一张表,不经常使用的字段放在另一张表中,用于提升查询性能
●实现方式:在任意一方加入外键,关联另一方主键,并且设置外键为唯一(UNIQUE)
*一对多(多对一)
*如:部门和员工
*一个部门对应多个员工,一个员工对应一个部门*
●实现方式:在多的一方建立外键,指向一的一方的主键
*多对多:
*如:商品和订单
*一个商品对应多个订单,一个订单包含多个商品
●实现方式:建立第三张中间表,中间至少包含两个外键,分别关联两方主键
数据库设计案例

分析

多表查询
1.内连接查询语法
2.外连接查询语法
3.子查询:
(查询中称嵌套查询为子查询)
事务
●数据库事务(Transaction)是一种机制、一个操作序列,包含了一组数据库操作命令
●事务把所有命令作为一个整体一起向系统提交或撤销请求,即这一组数据库命令要么同时成功,要么同时失败
●事务是一个不可分割的逻辑单元
——开启事务
START TRANSACTION; 或者BEGIN;
——提交事务
COMMIT;
——回滚事务
ROLLBACK;
事务四大特征(常见面试题)
边栏推荐
- Standard dialog qmessagebox
- JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory
- [Niuke discussion area] Chapter 7: building safe and efficient enterprise services
- 2021 OWASP top 6-10 collection
- Jmeter 界面如何汉化?
- Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
- Inspiration from "flying man" Jordan! Another "arena" opened by O'Neill
- Shell course summary
- 听过最自律的一句话: 那些我难以言表 不作声响
- B1021 个位数统计
猜你喜欢

Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes

ssm框架整合

pyside2____ 1. Installation and case listing

Mysql表的约束

JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area

Detailed description of polymorphism

2021 OWASP top 4: unsafe design

树莓派输出PWM波驱动舵机

Transaction database and its four characteristics, principle, isolation level, dirty read, unreal read, non repeatable read?

JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory
随机推荐
Transaction database and its four characteristics, principle, isolation level, dirty read, unreal read, non repeatable read?
The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
Invert a Binary Tree
Quoted popular explanation
文件处理(IO)
素数筛选(埃氏筛法,区间筛法,欧拉筛法)
Slashes / and backslashes involved in writing code\
标准对话框 QMessageBox
文件对话框
pyside2____ 1. Installation and case listing
B1023 组个最小数
Installation and template setting of integrated development environment pychar
Counting Nodes in a Binary Search Tree
Deep Qt5 signal slot new syntax
34. 分析flexible.js
整合SSM
Static and final keyword learning demo exercise
Bean的生命周期&&依赖注入*依赖自动装配
Introduction to MySQL optimization
JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area