MySQL - 3. 创建数据库表

建表
create table player(
    id int identity,
    card_id char(18),
    name varchar(10),
    sex enum('',''),
    age tinyint,
    tel char(11),
    balance decimal(7,3)
    );
查看数据库下的所有表
show tables from football;
查看表结构
show columns from football;
查看表结构方式2
desc player;
查看创建表的完整语句
show create table player;
添加列
alter table player add club varchar(30);
在指定列后添加列
alter table player add club varchar(30) after name;
添加新列到最前面    
alter table player add player_id char(10) first;
修改列名    
alter table player change name new_name varchar(30);
修改列的数据类型
alter table player modify name varchar(25);
修改列的排列位置    
alter table player modify name varchar(10) after id;
删除列指定列
alter table player drop club;
修改表名    
alter table oldname rename to newname;
删除数据库表    
drop table test1,test2;
删除数据库表前检测表是否存在,不会报错    
drop table if not exists test1,test2;
清空表中数据,重置Identity(标识列,自增字段)
相当于自增列会被初始化,重新从1开始记录。
truncate table table_name

 

posted @ 2020-09-10 00:24  短戈行  阅读(155)  评论(0编辑  收藏  举报