INSERT QUERY IN POSTGRESQL

By    

 


INSERT QUERY IN POSTGRESQL

INSERT — create new rows in a table.

What is insert query?

The Insert command in the relational databases PostgreSQL, SQL Server, and Oracle's Structured Query Language (SQL) data manipulation language (DML) is often used. The insert command is used to add one or more rows with certain table column values to a database table.

How do you write an insert query?

The INSERT INTO statement has two fundamental syntaxes, which are shown below. 

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) 
VALUES (value1, value2, value3,...valueN);

These are the names of the columns in the table that you wish to enter the data into: column1, column2, column3,...columnN. 
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

If you are adding values to all of the table's columns, you might not need to specify the column(s) name in the SQL query. But make sure the data are arranged in the same order as the table's column order. 
CREATE TABLE Item
(  ItemId       BIGINT          PRIMARY KEY,
   ItemCode     VARCHAR(30)     NOT NULL,
   ItemName     VARCHAR(100)    NOT NULL
); 

Check created tables list in PostgreSQL database. Click here to check Postgres show tables.

Insert a single row into table item 

INSERT INTO item VALUES
(1, 'I001', 'Cabinet'); 

To insert multiple rows using the multirow VALUES syntax

INSERT INTO item (itemid, itemcode, itemname) VALUES
(2,'B6717', 'Tampopo'),
(3,'HG120', 'The Dinner Game');

 

Please visit other related articles



0 comments