SlideShare a Scribd company logo
sample.sql
-- START
-- SETUP Create user
CREATE USER tester1
IDENTIFIED BY Password11
DEFAULT TABLESPACE USERS
QUOTA 10M ON USERS;
-- Allow user to connect
GRANT CREATE SESSION TO tester1;
-- All user basic table privileges
-- GRANT resource to tester1;
-- Specific privileges
GRANT CREATE TABLE TO tester1;
GRANT CREATE VIEW TO tester1;
GRANT SELECT ANY TABLE TO tester1;
GRANT UPDATE ANY TABLE TO tester1;
GRANT INSERT ANY TABLE TO tester1;
GRANT DROP ANY TABLE TO tester1;
-- CONNECT
CONNECT tester1/Password11;
-- DROP TABLES
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE ORDER_LINES';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE ORDERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE
MUSIC_PRODUCTS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE CUSTOMERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
EXECUTE IMMEDIATE 'DROP VIEW
VIEW_PRODUCTS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
EXECUTE IMMEDIATE 'DROP VIEW
VIEW_ORDER_INFO';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
COMMIT;
-- CREATE TABLES
-- CREATE CUSTOMERS TABLE
CREATE TABLE CUSTOMERS (
CUSTOMER_ID INT,
FNAME VARCHAR2(20),
LNAME VARCHAR2(25),
EMAIL VARCHAR(50) NOT NULL UNIQUE,
CCARD_NUM VARCHAR2(80),
ED_EXPIRE_DAY CHAR(2),
EM_EXPIRE_MON CHAR(2),
EY_EXPIRE_YR CHAR(4),
STREET VARCHAR2(50),
CITY VARCHAR2(20),
STATE_CUST CHAR(2),
ZIPCODE INT,
PRIMARY KEY (CUSTOMER_ID),
CHECK (ED_EXPIRE_DAY BETWEEN 1 AND 31),
CHECK (EM_EXPIRE_MON BETWEEN 1 AND 12),
CHECK (EY_EXPIRE_YR > 2015)
);
-- CREATE MUSIC_PRODUCTS TABLE
CREATE TABLE MUSIC_PRODUCTS (
PRODUCT_ID INT,
PRODUCT_NAME VARCHAR2(30),
DESCRIPTION VARCHAR2(150),
ONHAND INT,
PRICE NUMBER(6,2),
PRIMARY KEY (PRODUCT_ID),
CHECK (PRICE >= 0),
CHECK (ONHAND >= 0)
);
-- CREATE ORDERS TABLE
CREATE TABLE ORDERS (
ORDER_ID INT,
ORDER_DATETIME TIMESTAMP,
CUSTOMER_ID INT,
PRIMARY KEY (ORDER_ID),
FOREIGN KEY (CUSTOMER_ID) REFERENCES
CUSTOMERS(CUSTOMER_ID)
);
-- CREATE ORDER_LINES TABLE
CREATE TABLE ORDER_LINES (
ORDER_LINE_ID INT,
ORDER_ID INT,
PRODUCT_ID INT,
NUM_ORDER INT,
PRIMARY KEY (ORDER_LINE_ID),
FOREIGN KEY (ORDER_ID) REFERENCES
ORDERS(ORDER_ID),
FOREIGN KEY (PRODUCT_ID) REFERENCES
MUSIC_PRODUCTS(PRODUCT_ID)
);
COMMIT;
-- DESC ALL TABLES
DESC CUSTOMERS;
DESC MUSIC_PRODUCTS;
DESC ORDERS;
DESC ORDER_LINES;
-- INSERT RECORDS
-- CUSTOMERS
INSERT ALL INTO CUSTOMERS
VALUES
(1001,'Abe', 'Smith', '[email protected]', '1234123412341234',
10, 2, 2017, '123 A Street', 'Palma', 'FL', 12345)
INTO CUSTOMERS VALUES
(1002,'Bob', 'Thomas', '[email protected]', '1233123312331244',
21, 5, 2017, '12th B Court', 'Orlandio', 'FL', 21223)
INTO CUSTOMERS VALUES
(1003,'Mark', 'Fisher', '[email protected]', '1111333322224444',
1, 2, 2018, '45th street south', 'Charlot', 'NC', 33212)
INTO CUSTOMERS VALUES
(1004,'Alice', 'Gomez', '[email protected]', '4444555536365757',
9, 3, 2019, '5th Blvd East', 'Talma', 'NC', 44244)
INTO CUSTOMERS VALUES
(1005,'Jill', 'Smith', '[email protected]', '1234123412341234',
10, 2, 2017, '123 A Street', 'Henderson', 'MD', 54345)
INTO CUSTOMERS VALUES
(1006,'Sandy', 'Blondie', '[email protected]',
'2222111121213333', 23, 12, 2019, '22nd Ave West',
'Sunnindale', 'CA', 23234)
SELECT 1 FROM DUAL;
COMMIT;
-- MUSIC_PRODUCTS
INSERT ALL INTO MUSIC_PRODUCTS
VALUES
(100,'Electric Guitar', 'A solid wood electric guitar made by
Gibson', 5, 1299.99)
INTO MUSIC_PRODUCTS VALUES
(101,'Acoustic Guitar', 'A solid wood Acoustic guitar made by
Yamaha', 10, 599.99)
INTO MUSIC_PRODUCTS VALUES
(102,'Snare', 'A popular snare drum made by ziljian', 7, 299.99)
INTO MUSIC_PRODUCTS VALUES
(103,'Bass Guitar', 'A solid wood electric bass guitar made by
Peavy', 4, 899.99)
INTO MUSIC_PRODUCTS VALUES
(104,'Amplifier', 'A solid wood caninet with 2 speakers. Very
loud and EXtreme!!', 12, 799.99)
SELECT 1 FROM DUAL;
COMMIT;
-- ORDERS
INSERT ALL INTO ORDERS
VALUES
(1, TIMESTAMP '2015-12-20 12:32:00', 1001)
INTO ORDERS VALUES
(2, TIMESTAMP '2015-12-24 02:15:30', 1003)
INTO ORDERS VALUES
(3, TIMESTAMP '2016-01-02 15:24:45', 1003)
INTO ORDERS VALUES
(4, TIMESTAMP '2016-01-15 16:05:41', 1004)
INTO ORDERS VALUES
(5, TIMESTAMP '2016-01-21 08:42:36', 1002)
SELECT 1 FROM DUAL;
COMMIT;
-- ORDER_LINES
INSERT ALL INTO ORDER_LINES
VALUES
(51, 1, 103, 1)
INTO ORDER_LINES VALUES
(52, 2, 102, 2)
INTO ORDER_LINES VALUES
(53, 2, 100, 2)
INTO ORDER_LINES VALUES
(54, 2, 104, 1)
INTO ORDER_LINES VALUES
(55, 5, 101, 1)
SELECT 1 FROM DUAL;
COMMIT;
-- SELECT TEST
SET LINESIZE 350
-- SELECT * FROM CUSTOMERS;
-- SELECT * FROM MUSIC_PRODUCTS;
-- SELECT * FROM ORDERS;
-- SELECT * FROM ORDER_LINES;
-- CREATE VIEW
CREATE VIEW VIEW_ORDER_INFO
AS
SELECT ORDERS.ORDER_ID, C.CUSTOMER_ID, C.FNAME,
C.LNAME, MP.PRODUCT_NAME, OLINE.NUM_ORDER,
MP.PRICE AS PRICE_PER
FROM CUSTOMERS C, MUSIC_PRODUCTS MP, ORDERS,
ORDER_LINES OLINE
WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID
AND ORDERS.ORDER_ID = OLINE.ORDER_ID
AND OLINE.PRODUCT_ID = MP.PRODUCT_ID
AND ORDERS.ORDER_ID = 2
;
COMMIT;
-- SELECT STATEMENTS 7 TOTAL
-- 0 TEST VIEW
SELECT * FROM VIEW_ORDER_INFO;
-- 1 GET PRODUCT TOTAL FROM VIEW
SELECT PRODUCT_NAME, SUM(NUM_ORDER *
PRICE_PER) AS PRODUCT_TOTAL
FROM VIEW_ORDER_INFO
GROUP BY PRODUCT_NAME;
-- 2 GET ORDER TOTAL FROM VIEW
SELECT SUM(NUM_ORDER * PRICE_PER) AS
ORDER_TOTAL
FROM VIEW_ORDER_INFO;
-- 3 GET ALL ORDERS
SELECT C.CUSTOMER_ID, C.FNAME, C.LNAME,
ORDERS.*
FROM CUSTOMERS C, ORDERS
WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID
ORDER BY ORDERS.ORDER_ID;
-- 4 GET ORDERS FROM CUSTTOMER_ID = 1003, TO
SHOW MULTIPLE ORDERS FROM SAME CUSTOMER
SELECT C.CUSTOMER_ID, C.FNAME, C.LNAME,
ORDERS.*
FROM CUSTOMERS C, ORDERS
WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID
AND ORDERS.ORDER_ID IN (SELECT ORDER_ID FROM
ORDERS WHERE C.CUSTOMER_ID = 1003)
ORDER BY ORDERS.ORDER_ID;
-- 5 GET ALL ORDER TOTALS PER EACH ORDER IN
DATABASE
SELECT ORDERS.ORDER_ID, SUM(OLINE.NUM_ORDER *
MP.PRICE) AS ORDER_TOTAL
FROM MUSIC_PRODUCTS MP, ORDERS, ORDER_LINES
OLINE
WHERE ORDERS.ORDER_ID = OLINE.ORDER_ID
AND OLINE.PRODUCT_ID = MP.PRODUCT_ID
GROUP BY ORDERS.ORDER_ID
;
-- SET LINESIZE
SET LINESIZE 800
-- 6 GET ALL NON REPEATING COLUMNS ACROSS ALL
TABLES TO SHOW INFORMATION REGARDING EACH
CUSTOMER
SELECT C.*, MP.*, ORDERS.ORDER_ID,
ORDERS.ORDER_DATETIME, OLINE.ORDER_LINE_ID,
OLINE.NUM_ORDER
FROM CUSTOMERS C, MUSIC_PRODUCTS MP, ORDERS,
ORDER_LINES OLINE
WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID
AND ORDERS.ORDER_ID = OLINE.ORDER_ID
AND OLINE.PRODUCT_ID = MP.PRODUCT_ID;
-- END
sample.sql-- START-- SETUP Create userCREATE USER .docx

More Related Content

More from agnesdcarey33086

Sample Summaries of Emily Raine’s Why Should I Be Nice to You.docx
Sample Summaries of Emily Raine’s Why Should I Be Nice to You.docxSample Summaries of Emily Raine’s Why Should I Be Nice to You.docx
Sample Summaries of Emily Raine’s Why Should I Be Nice to You.docx
agnesdcarey33086
 
SAMPLEExecutive Summary The following report is an evalua.docx
SAMPLEExecutive Summary The following report is an evalua.docxSAMPLEExecutive Summary The following report is an evalua.docx
SAMPLEExecutive Summary The following report is an evalua.docx
agnesdcarey33086
 
Sample Student Industry AnalysisExecutive SummaryCom.docx
Sample Student Industry AnalysisExecutive SummaryCom.docxSample Student Industry AnalysisExecutive SummaryCom.docx
Sample Student Industry AnalysisExecutive SummaryCom.docx
agnesdcarey33086
 
SAMPLING MEAN DEFINITION The term sampling mean is.docx
SAMPLING MEAN  DEFINITION  The term sampling mean is.docxSAMPLING MEAN  DEFINITION  The term sampling mean is.docx
SAMPLING MEAN DEFINITION The term sampling mean is.docx
agnesdcarey33086
 
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxSAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
agnesdcarey33086
 
sampleReportt.docxPower Electronics Contents.docx
sampleReportt.docxPower Electronics            Contents.docxsampleReportt.docxPower Electronics            Contents.docx
sampleReportt.docxPower Electronics Contents.docx
agnesdcarey33086
 
Sample Workflow of Answering a Telephone in an OfficeInform .docx
Sample Workflow of Answering a Telephone in an OfficeInform .docxSample Workflow of Answering a Telephone in an OfficeInform .docx
Sample Workflow of Answering a Telephone in an OfficeInform .docx
agnesdcarey33086
 
Sample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docx
Sample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docxSample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docx
Sample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docx
agnesdcarey33086
 
SAMPLE Project (Answers and explanations are in red)I opened t.docx
SAMPLE Project (Answers and explanations are in red)I opened t.docxSAMPLE Project (Answers and explanations are in red)I opened t.docx
SAMPLE Project (Answers and explanations are in red)I opened t.docx
agnesdcarey33086
 
Sample Questions to Ask During an Informational Interview .docx
Sample Questions to Ask During an Informational Interview  .docxSample Questions to Ask During an Informational Interview  .docx
Sample Questions to Ask During an Informational Interview .docx
agnesdcarey33086
 
Sample Table.pdfTopic RatingPatients Goal Able to walk .docx
Sample Table.pdfTopic RatingPatients Goal Able to walk .docxSample Table.pdfTopic RatingPatients Goal Able to walk .docx
Sample Table.pdfTopic RatingPatients Goal Able to walk .docx
agnesdcarey33086
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 
Sample PowerPoint Flow Week 5Select a current product with which.docx
Sample PowerPoint Flow Week 5Select a current product with which.docxSample PowerPoint Flow Week 5Select a current product with which.docx
Sample PowerPoint Flow Week 5Select a current product with which.docx
agnesdcarey33086
 
Sample Of assignmentIntroductionComment by Jane Summers Introd.docx
Sample Of assignmentIntroductionComment by Jane Summers Introd.docxSample Of assignmentIntroductionComment by Jane Summers Introd.docx
Sample Of assignmentIntroductionComment by Jane Summers Introd.docx
agnesdcarey33086
 
Sample Access Control Policy1.Purpose2.Scope3.Pol.docx
Sample Access Control Policy1.Purpose2.Scope3.Pol.docxSample Access Control Policy1.Purpose2.Scope3.Pol.docx
Sample Access Control Policy1.Purpose2.Scope3.Pol.docx
agnesdcarey33086
 
SAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docx
SAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docxSAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docx
SAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docx
agnesdcarey33086
 
Sample Action Research Report 1 Effect of Technol.docx
Sample Action Research Report 1    Effect of Technol.docxSample Action Research Report 1    Effect of Technol.docx
Sample Action Research Report 1 Effect of Technol.docx
agnesdcarey33086
 
Sample Case with a report Dawit Zerom, Instructor Cas.docx
Sample Case with a report Dawit Zerom, Instructor  Cas.docxSample Case with a report Dawit Zerom, Instructor  Cas.docx
Sample Case with a report Dawit Zerom, Instructor Cas.docx
agnesdcarey33086
 
Salkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docx
Salkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docxSalkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docx
Salkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docx
agnesdcarey33086
 
Sales_Marketing_-_Riordan_9.docxSales & MarketingHome .docx
Sales_Marketing_-_Riordan_9.docxSales & MarketingHome  .docxSales_Marketing_-_Riordan_9.docxSales & MarketingHome  .docx
Sales_Marketing_-_Riordan_9.docxSales & MarketingHome .docx
agnesdcarey33086
 

More from agnesdcarey33086 (20)

Sample Summaries of Emily Raine’s Why Should I Be Nice to You.docx
Sample Summaries of Emily Raine’s Why Should I Be Nice to You.docxSample Summaries of Emily Raine’s Why Should I Be Nice to You.docx
Sample Summaries of Emily Raine’s Why Should I Be Nice to You.docx
 
SAMPLEExecutive Summary The following report is an evalua.docx
SAMPLEExecutive Summary The following report is an evalua.docxSAMPLEExecutive Summary The following report is an evalua.docx
SAMPLEExecutive Summary The following report is an evalua.docx
 
Sample Student Industry AnalysisExecutive SummaryCom.docx
Sample Student Industry AnalysisExecutive SummaryCom.docxSample Student Industry AnalysisExecutive SummaryCom.docx
Sample Student Industry AnalysisExecutive SummaryCom.docx
 
SAMPLING MEAN DEFINITION The term sampling mean is.docx
SAMPLING MEAN  DEFINITION  The term sampling mean is.docxSAMPLING MEAN  DEFINITION  The term sampling mean is.docx
SAMPLING MEAN DEFINITION The term sampling mean is.docx
 
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxSAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
 
sampleReportt.docxPower Electronics Contents.docx
sampleReportt.docxPower Electronics            Contents.docxsampleReportt.docxPower Electronics            Contents.docx
sampleReportt.docxPower Electronics Contents.docx
 
Sample Workflow of Answering a Telephone in an OfficeInform .docx
Sample Workflow of Answering a Telephone in an OfficeInform .docxSample Workflow of Answering a Telephone in an OfficeInform .docx
Sample Workflow of Answering a Telephone in an OfficeInform .docx
 
Sample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docx
Sample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docxSample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docx
Sample Investment PropertyAverage InlandSan Diego HomeASSUMPTION.docx
 
SAMPLE Project (Answers and explanations are in red)I opened t.docx
SAMPLE Project (Answers and explanations are in red)I opened t.docxSAMPLE Project (Answers and explanations are in red)I opened t.docx
SAMPLE Project (Answers and explanations are in red)I opened t.docx
 
Sample Questions to Ask During an Informational Interview .docx
Sample Questions to Ask During an Informational Interview  .docxSample Questions to Ask During an Informational Interview  .docx
Sample Questions to Ask During an Informational Interview .docx
 
Sample Table.pdfTopic RatingPatients Goal Able to walk .docx
Sample Table.pdfTopic RatingPatients Goal Able to walk .docxSample Table.pdfTopic RatingPatients Goal Able to walk .docx
Sample Table.pdfTopic RatingPatients Goal Able to walk .docx
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Sample PowerPoint Flow Week 5Select a current product with which.docx
Sample PowerPoint Flow Week 5Select a current product with which.docxSample PowerPoint Flow Week 5Select a current product with which.docx
Sample PowerPoint Flow Week 5Select a current product with which.docx
 
Sample Of assignmentIntroductionComment by Jane Summers Introd.docx
Sample Of assignmentIntroductionComment by Jane Summers Introd.docxSample Of assignmentIntroductionComment by Jane Summers Introd.docx
Sample Of assignmentIntroductionComment by Jane Summers Introd.docx
 
Sample Access Control Policy1.Purpose2.Scope3.Pol.docx
Sample Access Control Policy1.Purpose2.Scope3.Pol.docxSample Access Control Policy1.Purpose2.Scope3.Pol.docx
Sample Access Control Policy1.Purpose2.Scope3.Pol.docx
 
SAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docx
SAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docxSAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docx
SAMPLE GED 501 RESEARCH PAPERTechnology Based Education How.docx
 
Sample Action Research Report 1 Effect of Technol.docx
Sample Action Research Report 1    Effect of Technol.docxSample Action Research Report 1    Effect of Technol.docx
Sample Action Research Report 1 Effect of Technol.docx
 
Sample Case with a report Dawit Zerom, Instructor Cas.docx
Sample Case with a report Dawit Zerom, Instructor  Cas.docxSample Case with a report Dawit Zerom, Instructor  Cas.docx
Sample Case with a report Dawit Zerom, Instructor Cas.docx
 
Salkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docx
Salkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docxSalkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docx
Salkind_datasetsCrab Scale Results.savSalkind_datasetsLess.docx
 
Sales_Marketing_-_Riordan_9.docxSales & MarketingHome .docx
Sales_Marketing_-_Riordan_9.docxSales & MarketingHome  .docxSales_Marketing_-_Riordan_9.docxSales & MarketingHome  .docx
Sales_Marketing_-_Riordan_9.docxSales & MarketingHome .docx
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

sample.sql-- START-- SETUP Create userCREATE USER .docx

  • 1. sample.sql -- START -- SETUP Create user CREATE USER tester1 IDENTIFIED BY Password11 DEFAULT TABLESPACE USERS QUOTA 10M ON USERS; -- Allow user to connect GRANT CREATE SESSION TO tester1; -- All user basic table privileges -- GRANT resource to tester1; -- Specific privileges
  • 2. GRANT CREATE TABLE TO tester1; GRANT CREATE VIEW TO tester1; GRANT SELECT ANY TABLE TO tester1; GRANT UPDATE ANY TABLE TO tester1; GRANT INSERT ANY TABLE TO tester1; GRANT DROP ANY TABLE TO tester1; -- CONNECT CONNECT tester1/Password11; -- DROP TABLES BEGIN EXECUTE IMMEDIATE 'DROP TABLE ORDER_LINES'; EXCEPTION WHEN OTHERS THEN NULL; END;
  • 3. / BEGIN EXECUTE IMMEDIATE 'DROP TABLE ORDERS'; EXCEPTION WHEN OTHERS THEN NULL; END; / BEGIN EXECUTE IMMEDIATE 'DROP TABLE MUSIC_PRODUCTS'; EXCEPTION WHEN OTHERS THEN NULL; END; / BEGIN EXECUTE IMMEDIATE 'DROP TABLE CUSTOMERS'; EXCEPTION WHEN OTHERS THEN NULL; END;
  • 4. / BEGIN EXECUTE IMMEDIATE 'DROP VIEW VIEW_PRODUCTS'; EXCEPTION WHEN OTHERS THEN NULL; END; / BEGIN EXECUTE IMMEDIATE 'DROP VIEW VIEW_ORDER_INFO'; EXCEPTION WHEN OTHERS THEN NULL; END; / COMMIT;
  • 5. -- CREATE TABLES -- CREATE CUSTOMERS TABLE CREATE TABLE CUSTOMERS ( CUSTOMER_ID INT, FNAME VARCHAR2(20), LNAME VARCHAR2(25), EMAIL VARCHAR(50) NOT NULL UNIQUE, CCARD_NUM VARCHAR2(80), ED_EXPIRE_DAY CHAR(2), EM_EXPIRE_MON CHAR(2), EY_EXPIRE_YR CHAR(4), STREET VARCHAR2(50), CITY VARCHAR2(20), STATE_CUST CHAR(2), ZIPCODE INT, PRIMARY KEY (CUSTOMER_ID), CHECK (ED_EXPIRE_DAY BETWEEN 1 AND 31), CHECK (EM_EXPIRE_MON BETWEEN 1 AND 12),
  • 6. CHECK (EY_EXPIRE_YR > 2015) ); -- CREATE MUSIC_PRODUCTS TABLE CREATE TABLE MUSIC_PRODUCTS ( PRODUCT_ID INT, PRODUCT_NAME VARCHAR2(30), DESCRIPTION VARCHAR2(150), ONHAND INT, PRICE NUMBER(6,2), PRIMARY KEY (PRODUCT_ID), CHECK (PRICE >= 0), CHECK (ONHAND >= 0) ); -- CREATE ORDERS TABLE CREATE TABLE ORDERS ( ORDER_ID INT,
  • 7. ORDER_DATETIME TIMESTAMP, CUSTOMER_ID INT, PRIMARY KEY (ORDER_ID), FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMERS(CUSTOMER_ID) ); -- CREATE ORDER_LINES TABLE CREATE TABLE ORDER_LINES ( ORDER_LINE_ID INT, ORDER_ID INT, PRODUCT_ID INT, NUM_ORDER INT, PRIMARY KEY (ORDER_LINE_ID), FOREIGN KEY (ORDER_ID) REFERENCES ORDERS(ORDER_ID), FOREIGN KEY (PRODUCT_ID) REFERENCES MUSIC_PRODUCTS(PRODUCT_ID) );
  • 8. COMMIT; -- DESC ALL TABLES DESC CUSTOMERS; DESC MUSIC_PRODUCTS; DESC ORDERS; DESC ORDER_LINES; -- INSERT RECORDS -- CUSTOMERS INSERT ALL INTO CUSTOMERS VALUES (1001,'Abe', 'Smith', '[email protected]', '1234123412341234', 10, 2, 2017, '123 A Street', 'Palma', 'FL', 12345) INTO CUSTOMERS VALUES (1002,'Bob', 'Thomas', '[email protected]', '1233123312331244',
  • 9. 21, 5, 2017, '12th B Court', 'Orlandio', 'FL', 21223) INTO CUSTOMERS VALUES (1003,'Mark', 'Fisher', '[email protected]', '1111333322224444', 1, 2, 2018, '45th street south', 'Charlot', 'NC', 33212) INTO CUSTOMERS VALUES (1004,'Alice', 'Gomez', '[email protected]', '4444555536365757', 9, 3, 2019, '5th Blvd East', 'Talma', 'NC', 44244) INTO CUSTOMERS VALUES (1005,'Jill', 'Smith', '[email protected]', '1234123412341234', 10, 2, 2017, '123 A Street', 'Henderson', 'MD', 54345) INTO CUSTOMERS VALUES (1006,'Sandy', 'Blondie', '[email protected]', '2222111121213333', 23, 12, 2019, '22nd Ave West', 'Sunnindale', 'CA', 23234) SELECT 1 FROM DUAL; COMMIT; -- MUSIC_PRODUCTS INSERT ALL INTO MUSIC_PRODUCTS VALUES
  • 10. (100,'Electric Guitar', 'A solid wood electric guitar made by Gibson', 5, 1299.99) INTO MUSIC_PRODUCTS VALUES (101,'Acoustic Guitar', 'A solid wood Acoustic guitar made by Yamaha', 10, 599.99) INTO MUSIC_PRODUCTS VALUES (102,'Snare', 'A popular snare drum made by ziljian', 7, 299.99) INTO MUSIC_PRODUCTS VALUES (103,'Bass Guitar', 'A solid wood electric bass guitar made by Peavy', 4, 899.99) INTO MUSIC_PRODUCTS VALUES (104,'Amplifier', 'A solid wood caninet with 2 speakers. Very loud and EXtreme!!', 12, 799.99) SELECT 1 FROM DUAL; COMMIT; -- ORDERS INSERT ALL INTO ORDERS VALUES
  • 11. (1, TIMESTAMP '2015-12-20 12:32:00', 1001) INTO ORDERS VALUES (2, TIMESTAMP '2015-12-24 02:15:30', 1003) INTO ORDERS VALUES (3, TIMESTAMP '2016-01-02 15:24:45', 1003) INTO ORDERS VALUES (4, TIMESTAMP '2016-01-15 16:05:41', 1004) INTO ORDERS VALUES (5, TIMESTAMP '2016-01-21 08:42:36', 1002) SELECT 1 FROM DUAL; COMMIT; -- ORDER_LINES INSERT ALL INTO ORDER_LINES VALUES (51, 1, 103, 1) INTO ORDER_LINES VALUES
  • 12. (52, 2, 102, 2) INTO ORDER_LINES VALUES (53, 2, 100, 2) INTO ORDER_LINES VALUES (54, 2, 104, 1) INTO ORDER_LINES VALUES (55, 5, 101, 1) SELECT 1 FROM DUAL; COMMIT; -- SELECT TEST SET LINESIZE 350 -- SELECT * FROM CUSTOMERS; -- SELECT * FROM MUSIC_PRODUCTS; -- SELECT * FROM ORDERS; -- SELECT * FROM ORDER_LINES;
  • 13. -- CREATE VIEW CREATE VIEW VIEW_ORDER_INFO AS SELECT ORDERS.ORDER_ID, C.CUSTOMER_ID, C.FNAME, C.LNAME, MP.PRODUCT_NAME, OLINE.NUM_ORDER, MP.PRICE AS PRICE_PER FROM CUSTOMERS C, MUSIC_PRODUCTS MP, ORDERS, ORDER_LINES OLINE WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID AND ORDERS.ORDER_ID = OLINE.ORDER_ID AND OLINE.PRODUCT_ID = MP.PRODUCT_ID AND ORDERS.ORDER_ID = 2 ; COMMIT;
  • 14. -- SELECT STATEMENTS 7 TOTAL -- 0 TEST VIEW SELECT * FROM VIEW_ORDER_INFO; -- 1 GET PRODUCT TOTAL FROM VIEW SELECT PRODUCT_NAME, SUM(NUM_ORDER * PRICE_PER) AS PRODUCT_TOTAL FROM VIEW_ORDER_INFO GROUP BY PRODUCT_NAME; -- 2 GET ORDER TOTAL FROM VIEW SELECT SUM(NUM_ORDER * PRICE_PER) AS ORDER_TOTAL FROM VIEW_ORDER_INFO; -- 3 GET ALL ORDERS SELECT C.CUSTOMER_ID, C.FNAME, C.LNAME, ORDERS.* FROM CUSTOMERS C, ORDERS
  • 15. WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID ORDER BY ORDERS.ORDER_ID; -- 4 GET ORDERS FROM CUSTTOMER_ID = 1003, TO SHOW MULTIPLE ORDERS FROM SAME CUSTOMER SELECT C.CUSTOMER_ID, C.FNAME, C.LNAME, ORDERS.* FROM CUSTOMERS C, ORDERS WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID AND ORDERS.ORDER_ID IN (SELECT ORDER_ID FROM ORDERS WHERE C.CUSTOMER_ID = 1003) ORDER BY ORDERS.ORDER_ID; -- 5 GET ALL ORDER TOTALS PER EACH ORDER IN DATABASE SELECT ORDERS.ORDER_ID, SUM(OLINE.NUM_ORDER * MP.PRICE) AS ORDER_TOTAL FROM MUSIC_PRODUCTS MP, ORDERS, ORDER_LINES OLINE WHERE ORDERS.ORDER_ID = OLINE.ORDER_ID AND OLINE.PRODUCT_ID = MP.PRODUCT_ID
  • 16. GROUP BY ORDERS.ORDER_ID ; -- SET LINESIZE SET LINESIZE 800 -- 6 GET ALL NON REPEATING COLUMNS ACROSS ALL TABLES TO SHOW INFORMATION REGARDING EACH CUSTOMER SELECT C.*, MP.*, ORDERS.ORDER_ID, ORDERS.ORDER_DATETIME, OLINE.ORDER_LINE_ID, OLINE.NUM_ORDER FROM CUSTOMERS C, MUSIC_PRODUCTS MP, ORDERS, ORDER_LINES OLINE WHERE C.CUSTOMER_ID = ORDERS.CUSTOMER_ID AND ORDERS.ORDER_ID = OLINE.ORDER_ID AND OLINE.PRODUCT_ID = MP.PRODUCT_ID; -- END