数据库测试:
mysql
DDL
测试1:
create table test(
test_id int,
test_price decimal,
test_name varchar(255) default 'xxx',
test_desc text,
test_img blob,
test_date datetime
);
create table test2 [column(字段1,字段2)][as] select * from test;
alter table test
add(
test_city varchar(255) default 'bj'
);
新增一列,可以省略圆括号。
alter test
add test_num int;
只能修改一行
alter table test
modify
test_num char(255);
//删除列
alter table test
drop test_num;
alter table test
rename core;
alter table core
change test_id test_num varchar(255);
清空数据库数据
truncate core;
drop table core;
测试2:约束
create table test(
test_id int not null,
test_name varchar(255) default 'xxx' not null,
test_sex(4) null
);
create test1
( test_id int not null;
test_id name varchar(255) unqiue,
);
create table test(
test_id int not null,
test_name varchar(255) default 'xxx' not null,
test_age int,
unique(test_name),
constraint test unique(test_age)
);
列级约束unique(字段名)
表级约束constratint 表名 unique(字段名)
//添加的是primary//非空+唯一
alter table test
add unique(test_id);
alter table test
drop index test_name;
alter table test
modify test_name varchar(255) unique;
create table teacher
(
teacher_id int auto_increment,
teacher_name varchar(255),
primary key(teacher_id)
);
列级约束:信息定义+ references 参照表(参照列)
表级约束: foreign key(外键字段) references 参照表(参照列)
contraint 约束名 foreign key(外键字段) references 参照表(参照列)
删除约束
alter table student
drop foreign key 约束名
check约束:
check()
建立索引:
create index index_name
on table_name(column),
删除索引:
drop index_name on tablename
视图:
create or repalce view 视图名 as 子查询
with check option
DML:
insert into(cloumn''') values("",""),('''),('')''';
update 表名 set 列1=值1,列2=值2;
delete from 表名 where 条件
select 列名1,列名2 from 表名 where condition
关于condtion
id>4
between A and B
in(list) 等于括号里多个值的任意之一。
like 支持通配符 a% _
is null 要求指定的值等于Null.
组合
and or
去重
select disrtinct 列名1,列名2 from 表名
orederby列名1desc,列名2
组函数:having子句使用
count
avg
max
min
sum
分组
group by
limt
select
from
where
groupby
orederby
having
limt