postgresql 删除重复数据案例详解(post的用法搭配)居然可以这样

随心笔谈2年前发布 admin
188 0 0

文章摘要

文章主要描述了对一个名为`test`的表进行结构设计和数据插入的操作。首先,文章删除了现有表`public.test`,然后创建了一个新的表,包含`id`(主键)、`name`和`age`三个字段。接着,文章插入了5条测试数据。最后,文章添加了一个主键约束`test_pkey`,确保`id`字段唯一性。总结来说,文章重点介绍了表结构设计、数据插入和主键约束的使用。



— —————————-
— Table structure for test
— —————————-
DROP TABLE IF EXISTS “public”.”test”;
CREATE TABLE “public”.”test” (
“id” int4 NOT NULL DEFAULT NULL,
“name” varchar(255) COLLATE “pg_catalog”.”default” DEFAULT NULL,
“age” int4 DEFAULT NULL
)
;

— —————————-
— Records of test
— —————————-
INSERT INTO “public”.”test” VALUES (1, ‘da’, 1);
INSERT INTO “public”.”test” VALUES (2, ‘da’, 12);
INSERT INTO “public”.”test” VALUES (3, ‘dd’, 80);
INSERT INTO “public”.”test” VALUES (4, ‘dd’, 80);
INSERT INTO “public”.”test” VALUES (5, ‘d1’, 13);

— —————————-
— Primary Key structure for table test
— —————————-
ALTER TABLE “public”.”test” ADD CONSTRAINT “test_pkey” PRIMARY KEY (“id”);

© 版权声明

相关文章