Primary Key is a key how data physically aligned in the memory system. It will give ability for fast retrieval of data.
Key aspects in primary key
- When you define a primary key PostgreSQL automatically creates a unique B-tree index on the columns available in the table.
- Use SERIAL or BIGSERIAL for auto-incrementing primary keys. These types automatically generate unique sequential values. refer (available data types in POSTGRESQL)
- Each table can have only one primary key
- but a primary key can consist of multiple columns (composite key).
Example for creating table
CREATE TABLE Wings
(
WingID uuid primary key,
WingName VARCHAR(100),
IsActive boolean
);Alter the existing table:
ALTER TABLE Wings ADD COLUMN ColID SERIAL PRIMARY KEY;
No comments:
Post a Comment