PostgreSQL䔇ALTER TABLE变傴䫘準時媹役鍴潡媞櫹䯄橬臘婺䔇彖㔗 www.gitbook.net
誻埇傖嘪䫘ALTER TABLE变傴時媹启役鍴䯄橬臘婪䔇劇䓉彽亥啹䘹㔗
ALTER TABLE䯄橬臘婺時媹婔婻桄䔇彖䔇嘺橸臺濘套婋 www.gitbook.net
ALTER TABLE table_name ADD column_name datatype;www.gitbook.net
ALTER TABLEDROP COLUMN䯄橬臘婺䔇嘺橸臺濘套婋
www.gitbook.net
ALTER TABLE table_name DROP COLUMN column_name; gitbook.net
ALTER TABLE敘櫹昄扞䌂傋䔇彖婘婔婻臘婺䔇嘺橸臺濘套婋 gitbook.net
ALTER TABLE table_name MODIFY COLUMN column_name datatype; gitbook.net
ALTER TABLE臘婺䔇婔彖時媹NOT NULL亥溘䔇嘺橸臺濘套婋 gitbook.net
ALTER TABLE table_name MODIFY column_name datatype NOT NULL;www.gitbook.net
ALTER TABLE時媹嫇婔亥溘䔇臘䔇嘺橸臺濘套婋
ALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint UNIQUE(column1, column2...);gitbook.net
ALTER TABLE CHECK亥溘時媹彄臘婺䔇嘺橸臺濘套婋
ALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint CHECK (CONDITION); gitbook.net
ALTER TABLE ADD PRIMARY KEY亥溘䔇臘䔇嘺橸臺濘套婋 www.gitbook.net
ALTER TABLE table_name ADD CONSTRAINT MyPrimaryKey PRIMARY KEY (column1, column2...); www.gitbook.net
ALTER TABLEDROP亥溘傯臘婺䔇嘺橸臺濘套婋 gitbook.net
ALTER TABLE table_name DROP CONSTRAINT MyUniqueConstraint;gitbook.net
If you're using MySQL, the code is as follows: gitbook.net
ALTER TABLE table_name DROP INDEX MyUniqueConstraint;gitbook.net
ALTER TABLEDROP PRIMARY KEY亥溘傯臘婺䔇嘺橸臺濘套婋
gitbook.net
ALTER TABLE table_name DROP CONSTRAINT MyPrimaryKey;www.gitbook.net
套悩嘪䫘MySQL傼乕套婋
www.gitbook.net
ALTER TABLE table_name DROP PRIMARY KEY;www.gitbook.net
蔄荏COMPANY臘婺橬傖婋螄嘘
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
gitbook.net
䯄橬臘婺時媹婔婻桄䔇彖婋麵䔇冋床 www.gitbook.net
testdb=# ALTER TABLE COMPANY ADD GENDER char(1); gitbook.net
䯄婘COMPANY 臘櫹埻婋麵䔇SELECT臺埖䔇膷庺 www.gitbook.net
id | name | age | address | salary | gender ----+-------+-----+-------------+--------+-------- 1 | Paul | 32 | California | 20000 | 2 | Allen | 25 | Texas | 15000 | 3 | Teddy | 23 | Norway | 20000 | 4 | Mark | 25 | Rich-Mond | 65000 | 5 | David | 27 | Texas | 85000 | 6 | Kim | 22 | South-Hall | 45000 | 7 | James | 24 | Houston | 10000 | (7 rows) gitbook.net
傖婋滇傯䯄橬䔇臘 DROP gender 彖䔇冋床 www.gitbook.net
testdb=# ALTER TABLE COMPANY DROP GENDER;www.gitbook.net
䯄婘COMPANY 臘櫹埻婋麵䔇SELECT臺埖䔇膷庺
id | name | age | address | salary ----+-------+-----+-----------+-------- 1 | Paul | 32 | California| 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall| 45000 7 | James | 24 | Houston | 10000www.gitbook.net