Chapter Data Definition

Table of Contents

Table Basics

Default Values

Generated Columns

Constraints

Check Constraints

 Not-Null Constraints

 Unique Constraints

 Primary Keys

 Foreign Keys

System Columns

Modifying Tables

 Adding a Column

 Removing a Column

 Adding a Constraint

 Removing a Constraint

 Changing a Column's Default Value

 Renaming a Column

 Renaming a Table

Privileges

Row Security Policies

Schemas

 Creating a Schema

 The Public Schema

 The Schema Search Path

 Schemas and Privileges

 The System Catalog Schema

 Usage Patterns

 Portability

Foreign Data

Other Database Objects

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, table partitioning, views, functions, and triggers.