0% found this document useful (0 votes)
18 views7 pages

University of Engineering and Technology, Taxila: Maam Rabia

The document describes creating and inserting records into multiple database tables related to customers, orders, order lines, and products using SQL commands. It includes creating tables, inserting values, and applying the MERGE command to merge data between the tables based on foreign key relationships. The tables created are CUSTOMER_T, ORDER_T, ORDER_LINE_T, and PRODUCT_T, with the MERGE command used to link data between them.

Uploaded by

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

University of Engineering and Technology, Taxila: Maam Rabia

The document describes creating and inserting records into multiple database tables related to customers, orders, order lines, and products using SQL commands. It includes creating tables, inserting values, and applying the MERGE command to merge data between the tables based on foreign key relationships. The tables created are CUSTOMER_T, ORDER_T, ORDER_LINE_T, and PRODUCT_T, with the MERGE command used to link data between them.

Uploaded by

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

UNIVERSITY OF ENGINEERING AND TECHNOLOGY,

TAXILA

SUBMITTED TO:
MAAM RABIA

SUBMITTED BY:
JAVARIA TABASSUM

REGISTRATION NO:
22-SE-33

ASSIGNMENT

DATABASE SYSTEMS (LAB)


Assignment #01

RECORD INSERTION
CUSTOMER_T:

CREATE TABLE CUSTOMER_T


(CUSTOMER_ID INTEGER PRIMARY KEY,
CUSTOMER_NAME CHAR(20),
CUSTOMER_ADDRESS VARCHAR(30),
CITY CHAR(20),
STATE CHAR(20),
POSTAL_CODE INTEGER);

INSERT INTO CUSTOMER_T (CUSTOMER_ID, CUSTOMER_NAME,


CUSTOMER_ADDRESS, CITY, STATE, POSTAL_CODE)
VALUES(&CUSTOMER_ID, '&CUSTOMER_NAME', '&CUSTOMER_ADDRESS', '&CITY',
'&STATE', &POSTAL_CODE);

SELECT*FROM CUSTOMER_T;
ORDER_T:

CREATE TABLE ORDER_T


(ORDER_ID INTEGER PRIMARY KEY,
ORDER_DATE DATE,
CUSTOMER_ID INT,FOREIGN KEY (CUSTOMER_ID) REFERENCES
CUSTOMER_T(CUSTOMER_ID));

INSERT INTO ORDER_T(ORDER_ID, ORDER_DATE, CUSTOMER_ID)


VALUES(&ORDER_ID, '&ORDER_DATE', &CUSTOMER_ID);

SELECT*FROM ORDER_T;

ORDER_LINE_T:
CREATE TABLE ORDER_LINE_T
(ORDER_ID INT,
FOREIGN KEY (ORDER_ID) REFERENCES ORDER_T(ORDER_ID),
PRODUCT_ID INTEGER PRIMARY KEY,
ORDERD_QUANTITY INTEGER);

INSERT INTO ORDER_LINE_T(ORDER_ID, PRODUCT_ID, ORDERD_QUANTITY)


VALUES(&ORDER_ID, &PRODUCT_ID, &ORDERD_QUANTITY);

SELECT*FROM ORDER_LINE_T;
PRODUCT_T:

CREATE TABLE PRODUCT_T


(PRODUCT_ID INT,
FOREIGN KEY (PRODUCT_ID) REFERENCES ORDER_LINE_T(PRODUCT_ID),
PRODUCT_DESCRIPTION CHAR(20),
PRODUCT_FINISH CHAR(20),
STANADARD_PRICE INT,
PRODUCT_LINE_ID INT);

INSERT INTO PRODUCT_T(PRODUCT_ID, PRODUCT_DESCRIPTION,


PRODUCT_FINISH, STANADARD_PRICE, PRODUCT_LINE_ID)
VALUES(&PRODUCT_ID, '&PRODUCT_DESCRIPTION', '&PRODUCT_FINISH',
&STANADARD_PRICE, &PRODUCT_LINE_ID);

SELECT*FROM PRODUCT_T;
APPLYING MERGE

MERGING CUSTOMER_T AND ORDER_T:

MERGE INTO ORDER_T o


USING CUSTOMER_T c
ON (o.CUSTOMER_ID = c.CUSTOMER_ID)
WHEN MATCHED THEN
UPDATE SET o.ORDER_DATE = o.ORDER_DATE
WHEN NOT MATCHED THEN
INSERT (ORDER_ID, ORDER_DATE, CUSTOMER_ID)
VALUES (1004, SYSDATE, c.CUSTOMER_ID);

ORDER_T MERGED:

MERGING ORDER_T AND ORDER_LINE_T:

MERGE INTO ORDER_LINE_T olt


USING ORDER_T o
ON (olt.ORDER_ID = o.ORDER_ID)
WHEN MATCHED THEN
UPDATE SET
olt.ORDERD_QUANTITY = NULL
WHEN NOT MATCHED THEN
INSERT (ORDER_ID, PRODUCT_ID, ORDERD_QUANTITY)
VALUES (o.ORDER_ID, :default_product_id, :default_ordered_quantity);
MERGING ORDER_LINE_T AND PRODUCT_T:

MERGE INTO PRODUCT_T p


USING ORDER_LINE_T ol
ON (p.PRODUCT_ID = ol.PRODUCT_ID)
WHEN MATCHED THEN
UPDATE SET
p.STANADARD_PRICE = 0,
p.PRODUCT_LINE_ID = ol.ORDER_ID
WHEN NOT MATCHED THEN
INSERT (PRODUCT_ID, PRODUCT_DESCRIPTION, PRODUCT_FINISH,
STANADARD_PRICE, PRODUCT_LINE_ID)
VALUES (ol.PRODUCT_ID, :default_product_description, :default_product_finish,
:default_stanadard_price, :default_product_line_id);

ORDER_LINE_T:
PRODUCT_T MERGED:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy