create table [模式名]表名
(
# 列定义
)
例:向study数据库中插入表person |
CREATE TABLE IF NOT EXISTS study.person ( id INT(11)NOTNULL AUTO_INCREMENT, username VARCHAR(20)NOTNULL, age INT, grade DOUBLE, addTime DATE, PRIMARYKEY(id) ) ENGINE = MyISAM DEFAULT CHARSET = UTF8; |
当没有在study数据库时,可以用下列2种方法 |
USE study;
CREATE TABLE IF NOT EXISTS person1 ( id INT(11)NOTNULL AUTO_INCREMENT, PRIMARYKEY(id) ) ENGINE = MyISAM DEFAULT CHARSET = UTF8; |
CREATE TABLE IF NOT EXISTS study.person ( id INT(11)NOTNULL AUTO_INCREMENT, PRIMARYKEY(id) ) ENGINE = MyISAM DEFAULT CHARSET = UTF8; |
MyBatis动态建表-SR |
<update id="createUserWorkflowTableInt" parameterType="com.xhuoaservice.model.vo.UserWorkflowVo"> create table If Not Exists ${userName}( localId int(10) NOT NULL AUTO_INCREMENT, id varchar(10) , memId varchar(10), nodeId varchar(10), docId varchar(10), createDate datetime, workStatus varchar(1), handleState varchar(10), bustleNum int(2), isFollow varchar(1), modifyTime timestamp NULL PRIMARY KEY (localId)
) </update> |
以上是常见建表语句,只是创建空表。使用子查询建表语句,则可以在建表时插入数据。
create table [模式名.]表名
# 创建StuCopy表,该表和student完全相同
CREATE TABLE StuCopy
AS SELECT *
FROM student;