-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02 Auto_incremeting.sql
More file actions
31 lines (21 loc) · 1.24 KB
/
02 Auto_incremeting.sql
File metadata and controls
31 lines (21 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- Serial fields / Auto Increment
/*
Create a table named automagic with the following fields:
An id field that is an auto incrementing serial field.
A name field that allows up to 32 characters but no more This field is required. (PostgreSQL Constraints)
A height field that is a floating point number that is required.
*/
CREATE TABLE automagic (
id SERIAL PRIMARY KEY,
name VARCHAR(32) NOT NULL,
height FLOAT NOT NULL
);
/*
The id column is defined as a "SERIAL" data type. This means that, for each new row added to the automagic table,
PostgreSQL will automatically assign a unique integer value to the id column. It's an auto-incrementing serial field that serves as the primary key.
The PRIMARY KEY constraint designates this column as the primary key, ensuring its uniqueness and facilitating efficient indexing for retrieval operations.
The NOT NULL constraints require that a value be provided for these columns when inserting data into the tables.
It ensures that the fields are mandatory and cannot be left empty.
This table is suitable for storing information about entities with names and heights,
and it ensures that each entry has a unique identifier (the id) and that both the name and height are provided for each entry.
*/