postgresqlHow do I create a table in PostgreSQL?
Creating a table in PostgreSQL is done with the CREATE TABLE
statement. Here is an example of creating a table called customers
:
CREATE TABLE customers (
customer_id serial PRIMARY KEY,
customer_name varchar(50) NOT NULL,
customer_email varchar(255) NOT NULL
);
This statement will create a table with three columns:
customer_id
: This column is a serial type and is set as the primary key.customer_name
: This column is a varchar type with a maximum of 50 characters and is set to not allow null values.customer_email
: This column is a varchar type with a maximum of 255 characters and is set to not allow null values.
Once the statement is executed, the table will be created and you can begin adding data to it.
Helpful links
More of Postgresql
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL's XMIN and XMAX features?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I store binary data in a Postgresql database using the bytea data type?
- How can I monitor PostgreSQL performance using Zabbix?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL on the Yandex Cloud platform?
- How do I set the PostgreSQL work_mem parameter?
See more codes...