The PostgreSQL CREATE TABLE articulation is utilized to make another table in any of the given information base.
Essential grammar of CREATE TABLE explanation is as per the following −
CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) );
Make TABLE is a catchphrase, advising the information base framework to make another table. The exceptional name or identifier for the table follows the CREATE TABLE articulation. At first, the unfilled table in the current information base is possessed by the client giving the order.
At that point, in sections, comes the rundown, characterizing every segment in the table and what kind of information type it is. The language structure will turn out to be clear with a model given beneath.
Coming up next is a model, which makes a COMPANY table with ID as essential key and NOT NULL are the imperatives demonstrating that these fields can't be NULL while making records in this table −
CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL );
Allow us to make one more table, which we will use in our activities in ensuing sections −
CREATE TABLE DEPARTMENT( ID INT PRIMARY KEY NOT NULL, DEPT CHAR(50) NOT NULL, EMP_ID INT NOT NULL );
You can check if your table has been made effectively utilizing \d order, which will be utilized to list down all the tables in a joined data set.
The above given PostgreSQL proclamation will deliver the accompanying outcome −
List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | company | table | postgres public | department | table | postgres (2 rows)
Use \d tablename to depict each table as demonstrated beneath −
testdb-# \d company
The above given PostgreSQL explanation will create the accompanying outcome −
Table "public.company" Column | Type | Modifiers -----------+---------------+----------- id | integer | not null name | text | not null age | integer | not null address | character(50) | salary | real | join_date | date | Indexes: "company_pkey" PRIMARY KEY, btree (id)