1.创建表的时候定义列级约束
Create table t1(col1 bigint primary key,name varchar(10) not null);Insert into t1 values(1,’u1’);Select * from t1;2.创建表的时候定义表级约束
Create table t2(col1 bigint,name varchar(10) not null,primary key(col1)); Insert into t2 values(2,’u2’);Select * from t2;3.为表的属性定义默认值
Create table t3(col1 int,name varchar(10) default ‘noman’);Insert into t3 values(3);Select * from t3;4.如果在创建表的时候,没有为某列定义默认值,缺省的默认值是空值null
Create table t4(col1 int primary key,name varchar(10));Insert into t4 values(4);Select * from t4;5.创建表时使用自增数据类型
Create table t5(col1 serial notnull,name varchar(20));Insert into t5(name) values(‘u51’);Insert into t5(name) values(‘u52’);Insert into t5(name) values(‘u53’);Select * from t5;6.使用现有的表创建新表
Create table t6 as select * from t5;Select * from t6;「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




