首先我们回忆联系上几节内容。先看
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 修改为新列名studentNO ALTER TABLE "public".student RENAME COLUMN studentid TO "studentNO";
ALTER TABLE student RENAME TO "Student";
参考资料:Postgresql参考手册9.6版第五章第五节等。
原文链接:https://www.f2er.com/postgresql/193458.html