系列文章目录
mysql语句
约束类
1.not null 非空约束
2.unique 唯一约束
3.primay key 非空唯一 => 主键
4.auto_increment 自动增长
5.foreign key 外键
6.default 设置默认值
创建库
create database 数据库名
使用库
use 数据库名
删除数据库
drop database 数据库名
创建数据表
create table 表名(
id int primary key auto_increment,
username varchar(50) not null,
password varchat(50) no null
);
删除数据表
drop table 表名
查看数据表属性
desc 表名
查询数据
- 查询数据库中的所有数据
- 条件查询
select * from 表名
select * from 表名 where username = 'admmer' and password = '123'
添加数据
- 添加完整数据
注意:sql语句中除了数值类型,其他类型都使用单引号
insert into 表名 value(null, '鞠婧祎', '女',26)
- 选择添加数据
insert into 表名 列名 values 值
- 批量添加数据
insert into 表名 values (null,'麦小兜',24),(null,'小点新',27)
删除数据
delete from 表名 where id = ?
修改数据
`uodate 表名 set 字段 = 修改的值 where id = ?`
操作数据库列
- 添加一列
alter table 表名 add 列名 类型
- 删除一列
alter table 表名 drop 列名` - 修改列名
alter table 表名 change 旧列名 新列名 类型
- 修改列类型
alter table 表名 modify 列名 新类型