mysql表結構操作
阿新 • • 發佈:2018-11-08
CREATE DATABASE sqltest; #DROP DATABASE sqltest; USE sqltest; CREATE TABLE USER ( id INT (10) UNSIGNED NOT NULL COMMENT 'Id', username VARCHAR (64) NOT NULL DEFAULT 'default' COMMENT '使用者名稱', PASSWORD VARCHAR (64) NOT NULL DEFAULT 'default' COMMENT '密碼', email VARCHAR (64) NOT NULL DEFAULT 'default' COMMENT '郵箱' ) COMMENT = '使用者表'; #複製表 CREATE TABLE vip_user AS SELECT * FROM user; DROP TABLE USER; #新增列 ALTER TABLE user ADD age int(3); #刪除列 ALTER TABLE user DROP COLUMN age; #修改列 ALTER TABLE `user` MODIFY COLUMN age tinyint; #新增主鍵 ALTER TABLE user ADD PRIMARY KEY (id); #刪除主鍵 ALTER TABLE user DROP PRIMARY KEY;