<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Schema on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/schema/</link><description>Recent content in Schema on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Wed, 08 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/schema/index.xml" rel="self" type="application/rss+xml"/><item><title>Find PostgreSQL Tables Without a Primary Key</title><link>https://www.postgresscripts.com/post/find-postgresql-tables-without-primary-key/</link><pubDate>Wed, 08 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/find-postgresql-tables-without-primary-key/</guid><description>
&lt;h2 id="how-to-find-postgresql-tables-without-a-primary-key"&gt;How to Find PostgreSQL Tables Without a Primary Key&lt;/h2&gt;
&lt;p&gt;A missing primary key is one of the most common and damaging database design oversights. Without a primary key, PostgreSQL has no reliable way to uniquely identify a row. This causes problems with logical replication, ORM frameworks, and application-level updates or deletes that may silently affect the wrong rows.&lt;/p&gt;
&lt;p&gt;This SQL query scans &lt;code&gt;information_schema&lt;/code&gt; to find every user table in your database that has no primary key or unique key constraint. Running it regularly is a simple way to catch schema problems before they reach production.&lt;/p&gt;</description></item><item><title>List All Views in a PostgreSQL Database with SQL</title><link>https://www.postgresscripts.com/post/list-postgresql-database-views/</link><pubDate>Tue, 07 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/list-postgresql-database-views/</guid><description>
&lt;h2 id="how-to-list-all-views-in-a-postgresql-database"&gt;How to List All Views in a PostgreSQL Database&lt;/h2&gt;
&lt;p&gt;Views are saved SQL queries stored in the database. A production database can accumulate dozens or hundreds of views over time — many created by developers, some by tools, and some that are no longer used. Knowing what views exist, which schema they belong to, and what they actually do is essential for documentation, auditing, and cleanup.&lt;/p&gt;
&lt;p&gt;This SQL script queries &lt;code&gt;information_schema.views&lt;/code&gt; to return every view in the current database, along with its schema and full SQL definition.&lt;/p&gt;</description></item><item><title>List PostgreSQL Enum Types and Their Values with SQL</title><link>https://www.postgresscripts.com/post/list-postgresql-enum-types/</link><pubDate>Mon, 06 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/list-postgresql-enum-types/</guid><description>
&lt;h2 id="how-to-list-all-enum-types-in-a-postgresql-database"&gt;How to List All Enum Types in a PostgreSQL Database&lt;/h2&gt;
&lt;p&gt;PostgreSQL supports user-defined enum types — a fixed ordered set of string values stored efficiently as integers. Enums are common in application schemas for columns like &lt;code&gt;status&lt;/code&gt;, &lt;code&gt;role&lt;/code&gt;, or &lt;code&gt;priority&lt;/code&gt;. Once created, their allowed values are managed in the database catalog, not in application code.&lt;/p&gt;
&lt;p&gt;Over time, a database can accumulate many enum types, some with values that no longer match what the application uses. This SQL script queries &lt;code&gt;pg_type&lt;/code&gt; and &lt;code&gt;pg_enum&lt;/code&gt; to list every enum type in the current database along with all of its allowed values.&lt;/p&gt;</description></item><item><title>List Foreign Key Constraints in PostgreSQL</title><link>https://www.postgresscripts.com/post/list-foreign-key-constraints-in-postgresql/</link><pubDate>Sun, 05 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/list-foreign-key-constraints-in-postgresql/</guid><description>
&lt;h2 id="list-foreign-key-constraints-in-postgresql"&gt;List Foreign Key Constraints in PostgreSQL&lt;/h2&gt;
&lt;p&gt;Foreign key constraints enforce referential integrity between tables. They guarantee that a value in one table's column always has a matching row in another table. Knowing which foreign keys exist — and how they are defined — is essential before dropping tables, renaming columns, or loading large datasets.&lt;/p&gt;
&lt;p&gt;This SQL query lists every foreign key in the public schema, showing the table that owns the constraint, the constraint name, and the full constraint definition including which columns it spans and which table it references.&lt;/p&gt;</description></item><item><title>List PostgreSQL Object Comments with SQL</title><link>https://www.postgresscripts.com/post/list-postgresql-object-comments/</link><pubDate>Sat, 04 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/list-postgresql-object-comments/</guid><description>
&lt;h2 id="list-postgresql-object-comments-with-sql"&gt;List PostgreSQL Object Comments with SQL&lt;/h2&gt;
&lt;p&gt;PostgreSQL allows you to attach plain-text comments to tables, columns, indexes, functions, and other database objects using the &lt;code&gt;COMMENT ON&lt;/code&gt; command. These comments are stored in the system catalog and are visible in psql, pgAdmin, and any tool that reads &lt;code&gt;pg_description&lt;/code&gt;. They are one of the most underused features for keeping a schema self-documenting.&lt;/p&gt;
&lt;p&gt;This SQL query lists comments on every column across all tables in your database, showing the schema, table name, column name, and the comment text. It is useful for auditing schema documentation, onboarding new team members, and verifying that comments are in place before a schema handover.&lt;/p&gt;</description></item></channel></rss>