表的操作
需要操作数据库中的表时,需要先使用该数据库:
use db_test;
1、查看表结构
desc 表名;
2、创建表
CREATE TABLE table_name (
field1 datatype,
field2 datatype,
field3 datatype
);
- 使用comment增加字段说明
示例:
create table stu_test (
id int,
name varchar(20) comment '姓名',
password varchar(50) comment '密码',
age int,
sex varchar(1),
birthday timestamp,
amout decimal(13,2),
resume text
);
3、删除表
DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name] ...
示例:
-- 删除 stu_test 表
drop table stu_test;
-- 如果存在 stu_test 表,则删除 stu_test 表
drop table if exists stu_test;