当前位置: 数据库>mysql
mysql 表维护与改造代码分享
来源: 互联网 发布时间:2014-10-04
本文导语: 改变列的数据类型 [sql] ALTER TABLE visitor MODIFY nam VARCHAR(30); 追加新列 [sql] ALTER TABLE visitor ADD age INT; ALTER TABLE visitor ADD age INT FIRST; ALTER TABLE visitor ADD age INT AFTER nam; 改变列的位置 [sql] ALTER TABLE visitor MODIFY age INT AFTER nam; 改变列名 和 ...
改变列的数据类型
[sql]
ALTER TABLE visitor MODIFY nam VARCHAR(30);
追加新列
[sql]
ALTER TABLE visitor ADD age INT;
ALTER TABLE visitor ADD age INT FIRST;
ALTER TABLE visitor ADD age INT AFTER nam;
改变列的位置
[sql]
ALTER TABLE visitor MODIFY age INT AFTER nam;
改变列名 和 类型
[sql]
ALTER TABLE visitor CHANGE birth birthday DATE;
删除列
[sql]
ALTER TABLE visitor DROP age;
表的复制
[sql]
CREATE TABLE customerH SELECT * FROM customer;
CREATE TABLE customerG LIKE customer;
INSERT INTO customerG SELECT * FROM customer;
INSERT INTO tb1G(no) SELECT bang FROM tb1;
表的删除
[sql]
DROP TABLE IF EXISTS customerG;
DROP TABLE customerG;
[sql]
ALTER TABLE visitor MODIFY nam VARCHAR(30);
追加新列
[sql]
ALTER TABLE visitor ADD age INT;
ALTER TABLE visitor ADD age INT FIRST;
ALTER TABLE visitor ADD age INT AFTER nam;
改变列的位置
[sql]
ALTER TABLE visitor MODIFY age INT AFTER nam;
改变列名 和 类型
[sql]
ALTER TABLE visitor CHANGE birth birthday DATE;
删除列
[sql]
ALTER TABLE visitor DROP age;
表的复制
[sql]
CREATE TABLE customerH SELECT * FROM customer;
CREATE TABLE customerG LIKE customer;
INSERT INTO customerG SELECT * FROM customer;
INSERT INTO tb1G(no) SELECT bang FROM tb1;
表的删除
[sql]
DROP TABLE IF EXISTS customerG;
DROP TABLE customerG;