sql编程入门
导入测试库:
文档地址: https://dev.mysql.com/doc/employee/en/sakila-structure.html
下载地址: https://github.com/datacharmer/test_db
导入测试库:
cd
mysql -uroot -p -S < employees.sql
库操作
增:create database test character set utf8;
删:drop database test;
改:alter database test character set gbk;
查
:show databases; 查看当前有哪些数据库
:show create database test; 查看创建test库的sql语句
表操作
增:create table t1 (id int)engine=innodb charset=utf8;
删:drop table t2;
改
:alter table t1 rename to t2; 修改表名称
:alter table t2 add name varchar(10); 添加新字段
:alter table t2 drop name; 删除字段
:alter table t2 change name title varchar(10); 修改字段名称
:alter table t2 modify title varchar(30); 修改字段类型约束
:alter table t2 convert to character set gbk; 修改字符集
:alter table t2 engine=myisam; 修改存储引擎
查
:show tables; 查看当前库下有哪些表
:show create table t1; 查看创建表的sql语句
:desc t1; 查看表结构
:show table status like 't1' \G; 查看表状态
数据操作
增
:insert into t1(id, name, gender) values(1, '张三', 'm');
:insert into t1(id, name, gender) values(null, '王五', 'm'),(null,'李四','m');
删:delete from t1 where id=1;
改:update t1 set name='ergou' where id=1;
查
:select * from t1;
:select name from t1;