CREATE table for PostgreSQL

Source: Internet
Author: User
Tags postgresql

The CREATE TABLE statement for PostgreSQL is used for creating a new table in any of the specified databases.

Grammar

The basic syntax for the CREATE table statement is as follows:

CREATE TABLE table_name (   column1 datatype,   column2 datatype,   column3 datatype,   ...   .. COLUMNN datatype,   or more columns));

Create TABLE is a new table that tells the database system keywords. The unique name or identity of the following table is the CREATE TABLE statement. The tables in the current database are initially empty, and commands that are issued by the owning user.

The list of each column is then defined within parentheses, and what type of data is in the table. Its syntax becomes clearer, the following example.

Instance

Here is an example that creates a student table ID as a primary key table and a NOT NULL constraint that shows that these fields cannot be null while creating records for that table:

CREATE TABLE  student (   ID              INT not      null,   NAME           TEXT not    null,            age INT not     NULL,   homeaddress     CHAR (   GRADE           )

You can verify that the successfully created using the \d command will be used to list all the tables in the attached database.

Use the \d + table name to describe each table as follows:

CREATE table for PostgreSQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.