mysql alter table 修正表敕令具體引見。本站提示廣大學習愛好者:(mysql alter table 修正表敕令具體引見)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql alter table 修正表敕令具體引見正文
MySQL ALTER語法以下:
ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...] alter_specification: ADD [COLUMN] create_definition [FIRST | AFTER column_name ] or ADD INDEX [index_name] (index_col_name,...) or ADD PRIMARY KEY (index_col_name,...) or ADD UNIQUE [index_name] (index_col_name,...) or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} or CHANGE [COLUMN] old_col_name create_definition or MODIFY [COLUMN] create_definition or DROP [COLUMN] col_name or DROP PRIMARY KEY or DROP INDEX index_name or RENAME [AS] new_tbl_name or table_options
上面來看幾個實例:
1、向表employee中添加Account_Number字段並設置其字段類型為INT
ALTER TABLE employee ADD COLUMN Account_Number INT
2、修正表employee中的ID字段為索引
ALTER TABLE employee ADD INDEX (ID)
3、修正表employee中的ID字段為主鍵PRIMARY KEY
ALTER TABLE employee ADD PRIMARY KEY (ID)
4、修正表employee中的ID字段為獨一索引UNIQUE
ALTER TABLE employee ADD UNIQUE (ID)
5、將employee表中的id字段重定名為salary並設置其數據類型為int
ALTER TABLE employee CHANGE ID salary INT
6、刪除employee表中的Customer_ID字段
ALTER TABLE employee DROP Customer_ID
7、刪除employee表中一切主鍵
ALTER TABLE employee DROP PRIMARY KEY
8、刪除employee表中字段Customer_ID的索引,只是將Customer_ID的索引撤消,不會刪除Customer_ID字段。
ALTER TABLE employee DROP INDEX Customer_ID
9、修正employee表中First_Name的字段類型為varchar(100)
ALTER TABLE employee MODIFY First_Name varchar(100)
10、將表employee重定名為Customer
ALTER TABLE employee RENAME Customer
11、多敕令寫在一路:
mysql> ALTER TABLE Books -> ADD PRIMARY KEY (BookID), -> ADD CONSTRAINT fk_1 FOREIGN KEY (PubID) REFERENCES Publishers (PubID), -> ADD COLUMN Format ENUM('paperback', 'hardcover') NOT NULL AFTER BookName;
感激浏覽,願望能贊助到年夜家,感謝年夜家對本站的支撐!