mysql中alter语句中change和modify的区别标签:mysqlalter,语句,name,index,alter,...,col,help From: https://blog.51cto.com/yetaotao/5800734
您可以使用CHANGEold_col_namecolumn_definition子句对列进行重命名。重命名时,需给定旧的和新的列名称和列当前的类型。例如:要把一个INTEGER列的名称从a变更到b,您需要如下操作:·mysql>ALTERTABLEt1CHANGE
本回答由提问者推荐
mysql查看alter的用法
mysql里面的man功能使用help命令,你可以输入下面的命令:
helpalter
helpaltertable
help命令显示使用帮助的几本方法:
mysql>help
ForinformationaboutMySQLproductsandservices,visit:
Fordeveloperinformation,includingtheMySQLReferenceManual,visit:
TobuyMySQLNetworkSupport,training,orotherproducts,visit:
ListofallMySQLcommands:
Notethatalltextcommandsmustbefirstonlineandendwith';'
?(\?)Synonymfor`help'.
clear(\c)Clearcommand.
connect(\r)Reconnecttotheserver.Optionalargumentsaredbandhost.
delimiter(\d)Setstatementdelimiter.NOTE:Takestherestofthelineasnew
delimiter.
ego(\G)Sendcommandtomysqlserver,displayresultvertically.
exit(\q)Exitmysql.Sameasquit.
go(\g)Sendcommandtomysqlserver.
help(\h)Displaythishelp.
notee(\t)Don'twriteintooutfile.
print(\p)Printcurrentcommand.
prompt(\R)Changeyourmysqlprompt.
quit(\q)Quitmysql.
rehash(\#)Rebuildcompletionhash.
source(\.)ExecuteanSQLscriptfile.Takesafilenameasanargument.
status(\s)Getstatusinformationfromtheserver.
tee(\T)Setoutfile[to_outfile].Appendeverythingintogivenoutfile.
use(\u)Useanotherdatabase.Takesdatabasenameasargument.
charset(\C)Switchtoanothercharset.Mightbeneededforprocessingbinlog
withmulti-bytecharsets.
warnings(\W)Showwarningsaftereverystatement.
nowarning(\w)Don'tshowwarningsaftereverystatement.
Forserversidehelp,type'helpcontents'
helpalter命令查看alter的几本功能
mysql>helpalter
Manyhelpitemsforyourrequestexist.
Tomakeamorespecificrequest,pleasetype'help
',
where
isoneofthefollowing
topics:
ALTERDATABASE
ALTERPROCEDURE
ALTERTABLE
ALTERVIEW
GRANT
SPATIAL
helpaltertable查看altertable的详细解释
mysql>helpaltertable
Name:'ALTERTABLE'
Description:
Syntax:
ALTER[IGNORE]TABLEtbl_name
alter_specification[,alter_specification]...
alter_specification:
table_option...
|ADD[COLUMN]col_namecolumn_definition[FIRST|AFTERcol_name]
|ADD[COLUMN](col_namecolumn_definition,...)
|ADD{INDEX|KEY}[index_name][index_type](index_col_name,...)
|ADD[CONSTRAINT[symbol]]
PRIMARYKEY[index_type](index_col_name,...)
|ADD[CONSTRAINT[symbol]]
UNIQUE[INDEX|KEY][index_name][index_type](index_col_name,...)
|ADD[FULLTEXT|SPATIAL][INDEX|KEY][index_name](index_col_name,...)
|ADD[CONSTRAINT[symbol]]
FOREIGNKEY[index_name](index_col_name,...)
reference_definition
|ALTER[COLUMN]col_name{SETDEFAULTliteral|DROPDEFAULT}
|CHANGE[COLUMN]old_col_namenew_col_namecolumn_definition
[FIRST|AFTERcol_name]
|MODIFY[COLUMN]col_namecolumn_definition[FIRST|AFTERcol_name]
|DROP[COLUMN]col_name
|DROPPRIMARYKEY
|DROP{INDEX|KEY}index_name
|DROPFOREIGNKEYfk_symbol
|DISABLEKEYS
|ENABLEKEYS
|RENAME[TO]new_tbl_name
|ORDERBYcol_name[,col_name]...
|CONVERTTOCHARACTERSETcharset_name[COLLATEcollation_name]
|[DEFAULT]CHARACTERSETcharset_name[COLLATEcollation_name]
|DISCARDTABLESPACE
|IMPORTTABLESPACE
index_col_name:
col_name[(length)][ASC|DESC]
index_type:
USING{BTREE|HASH|RTREE}
ALTERTABLEenablesyoutochangethestructureofanexistingtable.
Forexample,youcanaddordeletecolumns,createordestroyindexes,
changethetypeofexistingcolumns,orrenamecolumnsorthetable
itself.Youcanalsochangethecommentforthetableandtypeofthe
table.
doc/refman/5.0/en/alter-table.html
mysql查看alter的用法
mysql里面的man功能使用help命令,你可以输入下面的命令:
help alter
help alter table
help命令显示使用帮助的几本方法:
mysql> help
For information about MySQL products and services, visit:
For developer information, including the MySQL Reference Manual, visit:
To buy MySQL Network Support, training, or other products, visit:
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?(\?) Synonym for `help'.
clear(\c) Clear command.
connect(\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter. NOTE: Takes the rest of the line as new
delimiter.
ego(\G) Send command to mysql server, display result vertically.
exit(\q) Exit mysql. Same as quit.
go(\g) Send command to mysql server.
help(\h) Display this help.
notee(\t) Don't write into outfile.
print(\p) Print current command.
prompt(\R) Change your mysql prompt.
quit(\q) Quit mysql.
rehash(\#) Rebuild completion hash.
source(\.) Execute an SQL script file. Takes a file name as an argument.
status(\s) Get status information from the server.
tee(\T) Set outfile [to_outfile]. Append everything into given outfile.
use(\u) Use another database. Takes database name as argument.
charset(\C) Switch to another charset. Might be needed for processing binlog
with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type 'help contents'
help alter命令查看alter的几本功能
mysql> help alter
Many help items for your request exist.
To make a more specific request, please type 'help
',
where
is one of the following
topics:
ALTER DATABASE
ALTER PROCEDURE
ALTER TABLE
ALTER VIEW
GRANT
SPATIAL
help alter table查看alter table的详细解释
mysql> help alter table
Name: 'ALTER TABLE'
Description:
Syntax:
ALTER [IGNORE] TABLE tbl_name
alter_specification [, alter_specification] ...
alter_specification:
table_option ...
| ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name ]
| ADD [COLUMN] (col_name column_definition,...)
| ADD {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
PRIMARY KEY [index_type] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
UNIQUE [INDEX|KEY] [index_name] [index_type] (index_col_name,...)
| ADD [FULLTEXT|SPATIAL] [INDEX|KEY] [index_name] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
FOREIGN KEY [index_name] (index_col_name,...)
reference_definition
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
| CHANGE [COLUMN] old_col_name new_col_name column_definition
[FIRST|AFTER col_name]
| MODIFY [COLUMN] col_name column_definition [FIRST | AFTER col_name]
| DROP [COLUMN] col_name
| DROP PRIMARY KEY
| DROP {INDEX|KEY} index_name
| DROP FOREIGN KEY fk_symbol
| DISABLE KEYS
| ENABLE KEYS
| RENAME [TO] new_tbl_name
| ORDER BY col_name [, col_name] ...
| CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
| [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
| DISCARD TABLESPACE
| IMPORT TABLESPACE
index_col_name:
col_name [(length)] [ASC | DESC]
index_type:
USING {BTREE | HASH | RTREE}
ALTER TABLE enables you to change the structure of an existing table.
For example, you can add or delete columns, create or destroy indexes,
change the type of existing columns, or rename columns or the table
itself. You can also change the comment for the table and type of the
table.
URL: table authors
constraint upkcl_auidind primary key clustered (au_id)
数据库中alter是什么意思?
通过更改、添加或删除列和约束,重新分配分区,或者启用或禁用约束和触发器,从而修改表的定义。简单说就是修改表结构的。
CREATE TABLE doc_exa ( column_a INT) ;
ALTER TABLE doc_exa ADD column_b VARCHAR(20) NULL ;