0% found this document useful (0 votes)
15 views2 pages

INSERT&UPDATE

The document shows how to create and populate a table in SQL, including creating the table, inserting single and multiple rows of data, inserting into specific columns, updating and deleting rows, and dropping the table.

Uploaded by

clouditlab9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

INSERT&UPDATE

The document shows how to create and populate a table in SQL, including creating the table, inserting single and multiple rows of data, inserting into specific columns, updating and deleting rows, and dropping the table.

Uploaded by

clouditlab9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Reset table

CREATE OR REPLACE TABLE OUR_FIRST_DB.PUBLIC.ORDERS (


ORDER_ID VARCHAR (30),
AMOUNT INT,
PROFIT INT,
QUANTITY INT,
CATEGORY VARCHAR(30),
SUBCATEGORY VARCHAR(30));

// Insert single row


INSERT INTO OUR_FIRST_DB.PUBLIC.ORDERS
VALUES (1,0,0,0, 'None','None');

SELECT * FROM OUR_FIRST_DB.PUBLIC.ORDERS;

// Insert multiple rows


INSERT INTO OUR_FIRST_DB.PUBLIC.ORDERS
VALUES
(2,12,4,1, 'Garden','Flowers'),
(3,15,6,2, 'House','Kitchen'),
(4,11,2,1, 'House','Sleeping');

SELECT * FROM OUR_FIRST_DB.PUBLIC.ORDERS;

// Insert into specific columns


INSERT INTO OUR_FIRST_DB.PUBLIC.ORDERS
VALUES
(2,'Flowers'),
(3,'Kitchen'),
(4,'Sleeping');

INSERT INTO OUR_FIRST_DB.PUBLIC.ORDERS (ORDER_ID, SUBCATEGORY)


VALUES
(2,'Flowers'),
(3,'Kitchen'),
(4,'Sleeping');

INSERT INTO OUR_FIRST_DB.PUBLIC.ORDERS (ORDER_ID, SUBCATEGORY)


VALUES
(2,'Flowers'),
(3,'Kitchen'),
(4,'Sleeping');

INSERT INTO OUR_FIRST_DB.PUBLIC.ORDERS (ORDER_ID, SUBCATEGORY)


VALUES
(2,'Flowers'),
(3,'Kitchen'),
(4,'Sleeping');

//INSERT OVERWRITE - Truncates the table


INSERT OVERWRITE INTO OUR_FIRST_DB.PUBLIC.ORDERS (ORDER_ID, SUBCATEGORY)
VALUES
(20,'Flowers'),
(30,'Kitchen'),
(40,'Sleeping');
UPDATE OUR_FIRST_DB.PUBLIC.ORDERS
SET ORDER_ID=1
WHERE ORDER_ID=20;

// Truncate (removes all data in the table)

TRUNCATE TABLE OUR_FIRST_DB.PUBLIC.ORDERS;

// Drop Table
DROP TABLE OUR_FIRST_DB.PUBLIC.ORDERS;

You might also like