oracle增加约束和删除约束代码
时间: 2023-11-18 10:03:38 浏览: 91
批量增加和删除代码
增加约束的代码示例:
1. 添加主键约束
```
ALTER TABLE table_name ADD CONSTRAINT constraint_name PRIMARY KEY (column_name);
```
2. 添加唯一约束
```
ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column_name);
```
3. 添加外键约束
```
ALTER TABLE table_name ADD CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES other_table_name (other_column_name);
```
4. 添加检查约束
```
ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (condition);
```
删除约束的代码示例:
1. 删除主键约束
```
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
```
2. 删除唯一约束
```
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
```
3. 删除外键约束
```
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
```
4. 删除检查约束
```
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
```
阅读全文