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. Schemas
5.7.1. Creating a Schema
5.7.2. The Public Schema
5.7.3. The Schema Search Path
5.7.4. Schemas and Privileges
5.7.5. The System Catalog Schema
5.7.6. Usage Patterns
5.7.7. Portability
5.8. Inheritance
5.9. Partitioning
5.9.1. Overview
5.9.2. Implementing Partitioning
5.9.3. Managing Partitions
5.9.4. Partitioning and Constraint Exclusion
5.9.5. Alternative Partitioning Methods
5.9.6. Caveats
5.10. Other Database Objects
5.11. 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.