Ifnull(0,1)如果第一个函数为0输出第二个,不为空输出第一个
CONCAT函数用于将两个字符串连接起来
外键:
-- alter 增加外键 on delete cascade 级联删除
name varchar(15) unique, /* 唯一约束 , 可以不填写,如果填写,不能为重复*/
not null不能为空 default 默认值
CRUD增删改查:
添加:
Insert into set 字段名=值
replace/Insert into (表名)字段列表 value(值列表)
Insert 库.表 value(值列表)
Replace 插入数据如果有主键存在,修改数据
Load 加载数据
Ifnull(0,1)如果第一个函数为0输出第二个,不为空输出第一个
If(0,‘yes’,‘no’)
删除:
(表=结构+数据)
Drop table表名 删除表
Delete from 表名 删除数据 delete 一条记录一条记录删除,删除所有的时候,效率低,但它灵活 可以加上条件 会触发删除触发器
Truncate 表名 删除数据 truncate 直接截断数据,auto_increment 恢复默认 , 不触发删除触发器, 也没有影响行,删除所有的时候,效率高,只能删除截断数据
delete from t1 where name='李四'--根据条件删除
alter table t4 drop column name--删除数据字段
修改:
查询:
Select *from 表名 limit 2 –查询两条记录
-简单,在公司的真实项目不允许使用,如果使用sqlyog 会自动修改为 limit 0,1000 -- select * from 表名; select * from stu;
select s.id,s.dept from tv s ---s为表的别名
select name 姓名,60+1 成绩 From tv
-- where (3) null 运算条件 is null 或 is not null select * from stu where score = null; -- 语句没有错误,结果没有
-- where (4) in (1,2,3) not in (1,2,3)
-- where (5) between and not between and 一般用于 数字 日期 -- 查看用户年龄在1 到 25岁之间的人数
-- where (6) 模糊查询like %代表0个或多个符, _代表一个符号 -- 查询姓李学生信息
-- where (7) 正则表达式 关键字为 regexp