首先我们回忆联系上几节内容。先看
CREATE table student( studentID SERIAL PRIMARY KEY,---主键约束 studentname VARCHAR(20) NOT NulL,---非空约束 studentsex INT CHECK (studentsex = '0' OR studentsex ='1' ) DEFAulT 0,---默认值 studentbirthday DATE CHECK ( studentbirthday <CURRENT_TIMESTAMP ),---检查约束,表约束 studentaddress CHAR(30),studentadmissiontime DATE,---入学时间 CONSTRAINT checkstudentadmissiontimeandstudentbirthday CHECK (studentbirthday > studentadmissiontime ) ---检查约束,表约束);
下面代码练习删除已命名约束。
---删除约束checkstudentadmissiontimeandstudentbirthday ALTER table student DROP CONSTRAINT checkstudentadmissiontimeandstudentbirthday;---删除非空约束ALTER table "public".student ALTER ColUMN studentname DROP NOT NulL;
给列添加约束值。
---设置入学默认时间为当前时间ALTER table student ALTER ColUMN studentadmissiontime SET DEFAulT CURRENT_TIMESTAMP;---删除默认值ALTER table student ALTER ColUMN studentadmissiontime DROP DEFAulT;
为“保持原样”,请重新执行设置入学默认时间为当前时间。
修改列名称。
---修改列名称,将列名studentID 修改为新列名studentNOALTER table "public".student REname ColUMN studentID TO "studentNO";
修改表名称。
ALTER table student REname TO "Student";
参考资料:Postgresql参考手册9.6版第五章第五节等。
总结以上是内存溢出为你收集整理的PostgreSQL数据库日常学习笔记15-修改表全部内容,希望文章能够帮你解决PostgreSQL数据库日常学习笔记15-修改表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)