Below are the scripts to create,insert and delete with example:
Step1: Creating Product Taable:
Checking the values
in view:
Step1: Creating Product Taable:
Script Used to Crate
the table:
CREATE TABLE Product
(
ProductID varchar(100) NOT NULL,
ProductName varchar(50) NOT NULL,
ListPrice varchar(50),
Category INT NOT NULL,
PRIMARY KEY (ProductID)
);
Below is the structure for Created Product table:
Script Used:
describe Product;
Step2: Inserting values into Product Table:
Example:
Script used to
insert the values into Product table:
INSERT INTO Product
(ProductID,ProductName,ListPrice,Category)
VALUES
(300,'Wave Cruiser','$49.99',11)
Checking for values successfully inserted in
Product table:
Scripts to insert
all values:
Script to Insert
Values one by one column:
1) INSERT INTO Product
(ProductID,ProductName,ListPrice,Category)
VALUES
(299,'Chest','$99.99',10);
2)INSERT INTO Product
(ProductID,ProductName,ListPrice,Category)
VALUES
(300,'Wave Cruiser','$49.99',11);
3)INSERT INTO Product
(ProductID,ProductName,ListPrice,Category)
VALUES
(301,'Megaland Play Tent','$59.99',11);
4)INSERT INTO Product
(ProductID,ProductName,ListPrice,Category)
VALUES
(302,'Wind-Up Water Swimmer','$2.99',11);
5)INSERT INTO Product
(ProductID,ProductName,ListPrice,Category)
VALUES
(303,'Garmin Pocket or Vehicle GPS
Navigator','$609.99',12);
Below are the list of values inserted in table:
Step3: Update the
name of a product whose ID is 299 to "Small Chest"
Script Used for update:
update Product set ProductName ='Small Chest'
where ProductID=299;
To check for product successful update:
select * from product where ProductID=299;
Step4: Select all unique categories from product
table.
Script Used:
select distinct(Category)from Product;
Sep5: Delete all
products in category 12
Script Used: delete
Product where Category=12;
Check for table for successfully
deleted row:
Step6: Create view
Product_Category11 that will include only products from category 11
Script used for
creation of VIEW:
CREATE OR REPLACE VIEW Product_Category11 AS
SELECT *
FROM
Product
WHERE
Category=11;
Step7: Display all
products fromCategory11
select * from
Product where category=11
No comments:
Post a Comment