增加列:
alter table products add column description text;
alter table products add column description text check (description <> '');
删除列:
alter table products drop column description
alter table products drop column description cascade;
增加约束:
alter table products add check (name <> '');
alter table products add constraint some_name unique (product_no);
alter table products add foreign key (product_group_id) references product_groups;
移除约束:
alter table products drop constraint some_name;
alter table products alter column product_no drop not null;
修改默认值:
alter table products alter column price set default 7.77;
alter table products alter column price drop default;
修改数据类型:
alter table products alter column price type numeric(10,2);
列重命名:
alter table products rename column product_no to product_number;
表重命名:
alter table products rename to items;
修改所有者:
alter table table_name owner to new_owner;
本文介绍了SQL中对数据库表的操作,包括如何增加、删除列,设置和移除约束,修改默认值及数据类型,以及重命名列和表。这些基本操作对于数据库管理和维护至关重要。
912

被折叠的 条评论
为什么被折叠?



