数据库总结语句

1.数据库操作
create database 数据名;
drop database 数据库名;
show databases;
2.表的操作;
create table 表名(
列名 数据类型 属性 索引 注释
constraint 外键名 foreign key (外键列名称) references 主表名称(主表列名称)
)engine=innerdb ,charset=utf-8,comment=" ";
drop table 表名1,表名2;
alter table 表名 change 列名 新列名 新数据类型;
alter table 表名 modify 列名 新数据类型;
alter table 表名 add 列名 数据类型;
alter table 表名 drop 列名; 删除列
alter table 表名 rename to 新的表名;
alter table 表名 rename as 新的表名;
desc 表名; 显示表结构‘’
show tables;
use 数据库名;
select database();
3.数据库内容的增删改
insert into 表名(列名1,列名2,...列名n) values(值1,值2,...值n);
delete from 表名 [where 条件];
update 表名 set 列名1 = 值1, 列名2 = 值2,... [where 条件];
4.数据库的查询
select * from 表名;
5.创建索引
6.创建外键
add table 从表名 add constraint 外键名称 foreign key (外键字段名称) references 主表名称(主表列名称);
7.ALTER TABLE 表名 DROP FOREIGN KEY 外键名称;
ALTER TABLE 表名 DROP INDEX 索引名称;
show index from 表名;
8.setautocommit=o;
start transaction;
rollback;
commit;
【数据库总结语句】set autocommit=1;

    推荐阅读