ALTER TABLE table_name ADD PRIMARY KEY (column_name); 以下SQL 语句在 employees 表中添加了一个主键: 实例 ALTERTABLEemployees ADDPRIMARYKEY(employee_id); 6. 添加 FOREIGN KEY ALTER TABLE child_table ADD CONSTRAINT fk_name FOREIGN KEY (column_name) REFERENCES parent_table (column_name); 以下SQL...
mysql>ALTERTABLEtestalter_tblENGINE=MYISAM;mysql>SHOWTABLESTATUSLIKE'testalter_tbl'\G***1.row***Name:testalter_tblType:MyISAMRow_format:FixedRows:0Avg_row_length:0Data_length:0Max_data_length:25769803775Index_length:1024Data_free:0Auto_increment:NULLCreate_time:2007-06-03 08:04:36Update_tim...
ALTER TABLE modifies a table definition by altering, adding, or dropping columns and constraints. ALTER TABLE also reassigns and rebuilds partitions, or disables and enables constraints and triggers.
RENAME [TO] table_name表重命名。 RENAME {INDEX | KEY}重命名索引或键。 DROP [TABLEGROUP]删除表组。 DROP [FOREIGN KEY]删除外键。 [SET] table_option设置表级属性,可选以下参数: PRIMARY_ZONE:设置表的 Primary Zone。 REPLICA_NUM:设置表的副本数(暂不支持)。
【实例 2】使用 ALTER TABLE 修改表 tb_emp1 的结构,在一列 name 后添加一个 int 类型的字段 col2,输入的 SQL 语句和运行结果如下所示。 mysql> ALTER TABLE tb_emp1 -> ADD COLUMN col2 INT AFTER name; Query OK, 0 rows affected (0.50 sec) ...
ALTER TABLE tbl_name [alter_option [, alter_option] ...] [partition_options] alter_option: { table_options | ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name] | ADD [COLUMN] (col_name column_definition,...) | ADD {INDEX | KEY} [index_name] [index_type] (key_...
The following query adds a column named dept to the employee table. hive>ALTERTABLEemployeeADDCOLUMNS(dept STRING COMMENT'Department name'); -- 有一些文章里说 add columns dept STRING COMMENT 'comment' ;但是在一些高版本里,需要把你需要加的列放到括号里() ...
PARTITION分割區名稱INTOtable-name11ADDMATERIALIZEDQUERY具體化查詢定義ALTERMATERIALIZEDQUERY具體化查詢表格變更DROPMATERIALIZEDQUERYADD RESTRICT ON DROPDROP RESTRICT ON DROPACTIVATENOT LOGGED INITIALLYWITH EMPTY TABLEADD PERIODFOR期間定義DROP PERIODSYSTEM_TIMEADDSYSTEMVERSIONINGUSE HISTORY TABLEhistory-table-nameON ...
obclient>CREATETABLEtbl1(col1 VARCHAR2(10));Query OK,0rowsaffected obclient>ALTERTABLEtbl1RENAMECOLUMNcol1TOcol2;Query OK,0rowsaffected obclient>DESCRIBEtbl1;+---+---+---+---+---+---+|FIELD|TYPE|NULL|KEY|DEFAULT|EXTRA|+---+---+---+---+---+---+|COL2|VARCHAR2(10)|YES...
运行alter table 操作。在此示例中,将 middle_name 列添加到 employee 示例数据库的 employee 表中。 代码语言:javascript 复制 mysql>ALTERTABLEemployees.employeesADDCOLUMNmiddle_namevarchar(14)AFTERfirst_name;QueryOK,0rowsaffected(9.27sec)Records:0Duplicates:0Warnings:0 ...