今日学习了openGauss表管理的相关知识,在实验中,学会如何创建列级约束表,创建表级约束、创建自增列的表、创建默认列表。
#登录数据库
su - omm
gsql -r1、创建表的时候定义列级约束。
create table test1(
id int primary key,name varchar(30),score bigint);2、创建表的时候定义表级约束。
create table test2(
id int,name varchar(30),score bigint,
primary key(id));3、为表的属性定义默认值。
#创建表create table test3(
id int primary key,name varchar(30),score bigint default 100);#表中插入记录
insert into test3(id,name) values(1,'cherish'),(2,'rencai'),(3,'sibao');
#查询数据
select * from test3;
4、如果在创建表的时候,没有为某列定义默认值,缺省的默认值是空值null
#创建表
create table test4(id int primary key,name varchar(30),score bigint);#插入数据
insert into test4(id,name) values(1,'user1'),(2,'user2'),(3,'user3');#查询数据
select * from test4;
5、创建表时使用自增数据类型。
#创建表
create table test5
(id serial,name varchar not null,score bigint,
primary key(id));#插入记录
insert into test5(name,score) values('xiaohong',89),('xiaoming',90),('xiaoli',99);
#查询数据
select * from test5;

6、使用现有的表创建新表。
create table t1 as select * from test5;
select * from t1;
create table t2 as select * from test5 where 1=3;
select * from t2;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




