天天看点

[数据库]-- mysql建表语句

一、创建一个测试表

CREATE TABLE t_test(

  id  int(20) NOT NULL AUTO_INCREMENT comment          '自增长id',

  student_no          varchar(32) NOT NULL    comment          '学生编号',

  sys_time  TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,

  PRIMARY KEY (id,student_no)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;

二、再创建一个表

create table t_test2 as select * from t_test;                      //创建表,同时数据复制到新表中

create table t_test3 as select * from t_test where 1=0;  //创建表时,只创建表结构,数据不转移 

三、将t_test2表中的所有数据插入到表t_test3中

insert into t_test3 select * from t_test2;  

四、删除表内容(不删除表结构)

truncate table t_test3;