Setting up the tables required for DB interactions
In this recipe, you will learn how to create, change, and delete tables and other logical database constructs that compose a database schema.
Getting ready
The standard SQL statement for table creation looks as follows:
CREATE TABLE table_name ( column1_name data_type(size), column2_name data_type(size), column3_name data_type(size), .... );
Here, table_name
and column_name
have to be alphanumeric and unique (inside the schema) identifiers. The limitations for the names and possible data types are database-specific. For example, Oracle allows the table name to have 128 characters, while in PostgreSQL, the maximum length of the table name and column name is 63 characters. There are differences in the data types too, so read the database documentation.
How it works...
Here is an example of a command that creates the traffic_unit
table in PostgreSQL:
CREATE TABLE traffic_unit ( id SERIAL PRIMARY KEY, vehicle_type VARCHAR NOT NULL, horse_power...