第2章:SQL基础

DDL

创建数据库:create database test1;
显示数据库:show databases;
选择数据库: use test1;
删除数据库: drop database test1;
创建表:
create table table_name(
    -> column_name column_type constrains,
    -> ...
    -> );

查看表的定义: desc tablename;  或者   show columns from table_name;

查看创建表的SQL语句: show create table table_name \G;
\G : 按字段竖向排列

删除表: drop table table_name;

修改表: alter table table_name modify [column] column_definition [first | after] col_name;

修改(modify)字段定义: alter table emp modify column ename varchar(20);

增加(add)字段: alter table emp add column age int(3);  默认加在表的最后

删除(drop)字段: alter table emp drop column age;

字段(change)改名: alter table emp change age age1 int(4);  change可以改变字段名称,modify不行

字段位置修改: alter table emp add birth date after ename;

放在最前面 : alter table emp modify age1 int(3) first;

更改表名(rename): alter table emp rename emp1;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值