A table in relational database consists of rows and columns.
- Columns are fixed in order and each column has a unique name within a table.
- Rows can be unlimited but SQL does not guarantee the order in which rows are returned, unless you explicitly mention a sorting parameter like order by.
- Each column has a data type associated with it. This restricts the type of data that a column can store. For example, a column with data type integer will not accept string inputs. We will read more about data types in the next section.
Creating a table in PostgreSQL
Let us look at an example of creating a table in PostgreSQL.
CREATE TABLE author (id integer,name text);
The above statement creates a table named
author with two columns
id column has the data type
name column has the data type
Dropping a table in PostgreSQL
DROP TABLE author;
This will delete the table
author from the
And if you want to cascade delete all associated objects, you can make use of the following:
DROP TABLE author CASCADE;
We will look at use cases of
CASCADE when we look at relationships and foreign key constraints.
Did you find this page helpful?
Start with GraphQL on Hasura for Free
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs