1.数据库的创建 create
创建一个zss的数据库
create database zss;
2.数据库的删除 drop
DROP DATABASE zsstest;
3.创建数据表 create
在zsstest数据库创建一个wan_to_lan的表,其中包含id int类型长度为20,不能为null,payloads为longblob类型可为null。。。设置id为主键
CREATE TABLE zsstest.`wan_to_lan` ( `id` bigint(20) NOT NULL, `payloads` longblob NULL, `is_done` tinyint(4) NOT NULL, `create_time` datetime NOT NULL, `done_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) )
值得注意的是()里面最后一句话不要逗号
1.类型包含长度的,在类型后面加(括号),括号里面写长度
2.上一列写完加逗号
3.最后一列不要写逗号
4.在每一条SQL语句写完之后要加分号;
5.如果有外键关系,先创建主表
4.数据表的删除
删除zsstest数据库中wan_to_lan表
drop table zsstest.wan_to_lan;
在某些时候,我们可以在创建表之前来进行判断,若存在则删除此张表,不存在则创建
判断是否存在wan_to_lan的表,存在则删除
DROP TABLE IF EXISTS `wan_to_lan`;