当前位置:网站首页>mysql约束之默认约束default
mysql约束之默认约束default
2022-07-22 06:00:00 【Camellia——】
-- 数据库约束(约束表中一些字段)
-- 多表查询:笛卡尔乘积,内连接,外连接(左外/右外),子查询-- mysql约束
-- 默认约束:default
-- 非空约束:not null
-- 唯一约束:unique
-- 主键约束:primary key(非空约束唯一)-------自增长约束auto_increment(记录当前插入的记录数)
-- 外键:foreign keyUSE mydb_01;
-- 默认约束 defaultCREATE TABLE stu (
id INT,
NAME VARCHAR (20),
gender VARCHAR (10)
) ;SELECT * FROM stu;
-- 正常情况插入数据
INSERT INTO stu (id, NAME, gender)
VALUES
(1, '张三', '男'),
(2, '李四', '男');-- 如果插入数据的时候,给某个字段没有插入数据,默认值null
INSERT INTO stu (id, NAME)
VALUES
(3, '丽萨') ;
-- 给当前字段添加默认约束,如果给当前字段不插入数据,默认约束就会起作用
-- 修改表中的字段类型
ALTER TABLE stu MODIFY gender VARCHAR(10) DEFAULT '男';DELETE FROM stu WHERE id=3;
DROP TABLE stu;-- 创建表的时候添加默认约束
CREATE TABLE stu(
id INT,
NAME VARCHAR(20),
gender VARCHAR(10) DEFAULT '男'
);
边栏推荐
- NFS network file system
- 电子信息工程专业毕设题目选题推荐
- ABAQUS realizes modal calculation of two degree of freedom vibration system
- GMT 0009-2012 data format go language operation
- 活动推荐| Apache Pulsar 在 vivo 的探索与实践 即将开播
- vim入门
- UE4 merge static mesh body
- UE4 keyboard keys realize door opening and closing
- 14-多线程1
- UE4 set night (update skysphere according to directionallight direction)
猜你喜欢
随机推荐
GMT 0009-2012数据格式-GO语言操作
JS的DOM操作——事件代理
Simple use of UE4 terrain tool
UE4 面试基础知识(三)
flask框架添加异步任务处理模型任务
15_ Additional models
Abaqus实现二自由度振动系统模态计算
DOF depth of field Foundation
The difference between final, finally and finalize
JSON_EXTRACT返回不正确问题
MATLAB函数:filtfilt——零相位数字滤波
LVS负载均衡群集
怎么使用js实现计算器和计时器功能
Getting started with VIM
Server network performance tuning tool
Can0 transceiver + receive interrupt configuration and baud rate calculation of gd32f470 (detailed)
UE4 set night (update skysphere according to directionallight direction)
How to implement Apache's built-in AB stress testing tool
Xshell Plus6下载及安装使用的方法
vivo官网APP全机型UI适配方案