Creating a database structure
After the database is created, the following three SQL statements will allow you to create and change the database structure. This is done through database entities, such as a table, function, or constraint:
- The
CREATE
statement creates the database entity. - The
ALTER
statement changes the database entity. - The
DROP
statement deletes the database entity.
There are also various SQL statements that allow you to inquire about each database entity. Such statements are database-specific and, typically, they are only used in a database console. For example, in the PostgreSQL console, \d <table>
can be used to describe a table, while \dt
lists all the tables. Refer to your database documentation for more details.
To create a table, you can execute the following SQL statement:
CREATE TABLE tablename ( column1 type1, column2 type2, ... );
The limitations for a table name, column names, and types of values that can be used depend...