今日学习了openGauss表管理的相关知识,在数据库中如何对表结构进行修改。
#登录数据库
su - omm
gsql -r
1、创建表,为表添加字段。
#创建表
create table t1(
id int primary key,
name varchar(30) not null,
score bigint default 100);#添加字段
alter table t1 add column sex boolean;

2、删除表中已有的字段。
alter table t1 drop column sex;
3、删除表中已有的约束,添加约束。
#删除主键约束
alter table t1 drop constraint t1_pkey;

#添加主键约束
alter table t1 add constraint t1_pkey primary key(id);
4、修改表字段的默认值。
alter table t1 alter column score set default 95;
5、修改字段的数据类型。
alter table t1 alter column id type bigint;
6、修改表字段的名字。
alter table t1 rename column score to stu_score;
7、修改表的名字。
alter table t1 rename to test1;
8、删除表。
drop table test1;「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




