sql所有的alter table语句
时间: 2023-06-13 18:03:10 浏览: 100
以下是 SQL 中所有的 ALTER TABLE 语句:
1. ADD COLUMN:向表中添加新的列
```
ALTER TABLE table_name ADD COLUMN column_name data_type;
```
2. DROP COLUMN:从表中删除列
```
ALTER TABLE table_name DROP COLUMN column_name;
```
3. MODIFY COLUMN:修改列的数据类型或大小
```
ALTER TABLE table_name MODIFY COLUMN column_name data_type;
```
4. RENAME COLUMN:重命名列
```
ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;
```
5. ADD CONSTRAINT:向表中添加约束
```
ALTER TABLE table_name ADD CONSTRAINT constraint_name constraint_type (column_name);
```
6. DROP CONSTRAINT:从表中删除约束
```
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
```
7. RENAME TABLE:重命名表
```
ALTER TABLE old_table_name RENAME TO new_table_name;
```
8. ADD PRIMARY KEY:向表中添加主键
```
ALTER TABLE table_name ADD PRIMARY KEY (column_name);
```
9. DROP PRIMARY KEY:从表中删除主键
```
ALTER TABLE table_name DROP PRIMARY KEY;
```
10. ADD FOREIGN KEY:向表中添加外键
```
ALTER TABLE table_name ADD FOREIGN KEY (column_name) REFERENCES other_table_name (other_column_name);
```
11. DROP FOREIGN KEY:从表中删除外键
```
ALTER TABLE table_name DROP FOREIGN KEY foreign_key_name;
```
阅读全文