Chapter 5. Data Definition

Table of Contents
5.1. Table Basics
5.2. Default Values
5.3. Constraints
5.3.1. Check Constraints
5.3.2. Not-Null Constraints
5.3.3. Unique Constraints
5.3.4. Primary Keys
5.3.5. Foreign Keys
5.3.6. Exclusion Constraints
5.4. System Columns
5.5. Modifying Tables
5.5.1. Adding a Column
5.5.2. Removing a Column
5.5.3. Adding a Constraint
5.5.4. Removing a Constraint
5.5.5. Changing a Column's Default Value
5.5.6. Changing a Column's Data Type
5.5.7. Renaming a Column
5.5.8. Renaming a Table
5.6. Privileges
5.7. Row Security Policies
5.8. Schemas
5.8.1. Creating a Schema
5.8.2. The Public Schema
5.8.3. The Schema Search Path
5.8.4. Schemas and Privileges
5.8.5. The System Catalog Schema
5.8.6. Usage Patterns
5.8.7. Portability
5.9. Inheritance
5.10. Partitioning
5.10.1. Overview
5.10.2. Implementing Partitioning
5.10.3. Managing Partitions
5.10.4. Partitioning and Constraint Exclusion
5.10.5. Alternative Partitioning Methods
5.10.6. Caveats
5.11. Foreign Data
5.12. Other Database Objects
5.13. Dependency Tracking

This chapter covers how one creates the database structures that will hold one's data. In a relational database, the raw data is stored in tables, so the majority of this chapter is devoted to explaining how tables are created and modified and what features are available to control what data is stored in the tables. Subsequently, we discuss how tables can be organized into schemas, and how privileges can be assigned to tables. Finally, we will briefly look at other features that affect the data storage, such as inheritance, views, functions, and triggers.