SlideShare a Scribd company logo
SQL
Database and Management System
By Manish
SQL
BASIS
COMMANDS
CREATE COMMAND:
1. EMPLOYEE TABLE:
CREATE TABLE EMPLOYEE
(
Fname varchar(15) not null,
Minitchar,
Lname varchar(15) not null,
ssn char(9) not null primarykey,
Bdate Date,
Addressvarchar(30),
Sex char,
Salarynumber,
Super_ssnchar(9) notnull ,
Dnoint
);
2. DEPARTMENT TABLE:
CREATE table department
(
Dname varchar(15) not null,
DnumberINTegernotnull PRIMARYKEY,
mgr_ssn char(9) not null,
mrg_start_date date
);
3. DEPT_LOCATION TABLE:
CREATE TABLE DEPT_LOCATION (
DnumberintegernotnulL,
Dlocationvarchar(15) not null,
PRIMARYKEY(Dnumber,Dlocation) );
4. WORKS_ON TABLE:
CREATE TABLE WORKS_ON
(
Essnchar(9) not null,
PnoINt,
hoursnumber,
PRIMARYKEY(ESSN,PNO)
);
5. PROJECT TABLE:
CREATE TABLE PROJECT
(
Pname varchar(10) not null,
PnumberINTnotnull PRIMARY KEY,
Plocationvarchar(15),
DmunINT
);
6. DEPENDENT TABLE:
CREATE TABLE DEPENDENT
(
Essn char(9) notnull,
Dependent_namevarchar(15) notnull PRIMARY KEY,
Sex char ,
Bdate time,
Relationshipvarchar(10)
);
INSERT COMMAND:
INSERTING TUPLES INTO EMPLOYEE TABLE:
1. INSERT INTO EMPLOYEE VALUES (‘John’,’B’,’Smith’,’123456789’,’1965-01-09’,’731 Fondren, Houston,
TX’,’M’,30000,333445555,5)
2. INSERT INTO EMPLOYEE VALUES (‘Franklin’,’T’,’Wong’,333445555’,’1955-13-08’,’638 Voss,Houston,
TX’,’M’,40000,888665555,5)
3. INSERT INTO EMPLOYEE VALUES (‘Alicia’,’J’,’Zelaya’,’999887777’,’1968-01-19’,’3321 Castle,Spring,
TX’,’F’,25000,987654321,4)
4. INSERT INTO EMPLOYEE VALUES (‘Jennifer’,’S’,’Wallace’,’987654321’,’1941-06-20’,’291 Berry,Bellaire,
TX’,’F’,43000,888665555,4)
5. INSERT INTO EMPLOYEE VALUES (‘Ramesh’,’K’,’Narayan’,’666884444’,’1962-09-15’,’975 FireOak, Humble,
TX’,’M’,38000,333445555,5)
6. INSERT INTO EMPLOYEE VALUES (‘Joyce’,’A’,’English’,’453453453’,’1972-07-31’,’5631 Rice
,Houston,TX’,’F’,25000,333445555,5)
7. INSERT INTO EMPLOYEE VALUES (‘Ahmed’,’V’,’Jabbar’,’987987987’,’1969-03-29’,’980 Dallas,Houston,
TX’,’M’,25000,987654321,4)
8. INSERT INTO EMPLOYEE VALUES (‘James’,’E’,’Borg’,’888665555’,’1937-11-10’,’450 Stone, Houston,
TX’,’M’,55000,NULL,1)
EMPLOYEE
Fname Minit Lname Ssn Bdate Address Sex Salary Super_ssn Dno
Ahmad V Jabbar 987987987 29-Mar-69 980,Dallas Houstontx M 25000 987654321 4
Alicia J Zelaya 999887777 19-Jan-68 3321 castle,springtx F 25000 987654321 4
FranklinT Wong 333445555 08-Dec-55 638 voss,Houstontx M 40000 888665555 5
James E Borg 888665555 10-Nov-37 450 Stone ,Houstontx M 55000 1
JenniferS Wallace 987654321 20-Jun-41 291 berry,Bellaire,tx F 43000 888665555 4
John B Smith 123456789 09-Jan-65 731 Fondren,Houston,TX M 30000 333445555 5
Joyce A English 453453453 31-Jul-72 5631 Rice,Houstontx F 25000 333445555 5
RameshK Narayan 666884444 15-Sep-62 975,Fire Oak ,Humble,tx M 38000 333445555 5
INSERTING TUPLES INTO DEPARTMENT TABLE:
1. INSERT INTO DEPARTMENT VALUES (‘Research’,5,333445555,’1988-05-22’)
2. INSERT INTO DEPARTMENT VALUES (‘Administration’,4,987654321,’1995-01-01’)
3. INSERT INTO DEPARTMENT VALUES (‘Headquarters’1,888665555,’1981-06-19’)
DEPARTMENT
Dname Dnumber Mgr_ssn Mgr_start_date
RESEARCH 1 888665555 19-Jun-81
Administration 4 987654321 01-Jan-95
Research 5 333445555 22-May-88
INSERTING TUPLES INTO DEPT_LOCATIONS TABLE:
1. INSERT INTO DEPT_LOCATIONS VALUES (1,’Houston’)
2. INSERT INTO DEPT_LOCATIONS VALUES (4,’Stafford’)
3. INSERT INTO DEPT_LOCATIONS VALUES (5,’Bellaire’)
4. INSERT INTO DEPT_LOCATIONS VALUES (5,’Sugarland’)
5. INSERT INTO DEPT_LOCATIONS VALUES (5,’Houston’)
INSERTING TUPLES INTO WORKS_ON TABLE:
1. INSERT INTO WORKS_ON VALUES(123456789,1,32.5)
2. INSERT INTO WORKS_ON VALUES(123456789,2,7.5)
3. INSERT INTO WORKS_ON VALUES(666884444,3,40.0)
4. INSERT INTO WORKS_ON VALUES(453453453,1,20.0)
5. INSERT INTO WORKS_ON VALUES(453453453,2,20.0)
6. INSERT INTO WORKS_ON VALUES(333445555,2,10.0)
7. INSERT INTO WORKS_ON VALUES(333445555,3,10.0)
8. INSERT INTO WORKS_ON VALUES(333445555,10,10.0)
9. INSERT INTO WORKS_ON VALUES(333445555,20,10.0)
10. INSERT INTO WORKS_ON VALUES(999887777,30,30.0)
11. INSERT INTO WORKS_ON VALUES(999887777,10,10.0)
12. INSERT INTO WORKS_ON VALUES(987987987,10,10.0)
13. INSERT INTO WORKS_ON VALUES(987987987,30,5.0)
14. INSERT INTO WORKS_ON VALUES(987654321,30,20.0)
15. INSERT INTO WORKS_ON VALUES(987654321,20,15.0)
16. INSERT INTO WORKS_ON VALUES(888665555,20,NULL)
INSERTING TUPLES INTO PROJECT TABLE:
1. INSERT INTO PROJECT VALUES(‘ProductX’,1,’Bellaire’,5)
2. INSERT INTO PROJECT VALUES(‘ProductY’,2,’Sugarland’,5)
3. INSERT INTO PROJECT VALUES(‘ProductZ’,3,’Houston’,5)
4. INSERT INTO PROJECT VALUES(‘Computerization’,10,’Stafford’,4)
5. INSERT INTO PROJECT VALUES(‘Reorganization’,20,’Houston’,1)
6. INSERT INTO PROJECT VALUES(‘Newbenefits’30,’Stafford’,4)
PROJECT
Pname Pnumber Plocation Dnum
ProductX 1 Bellaire 5
ProductY 2 Sugarland 5
ProductZ 3 Houston 5
Computerization 10 Stafford 4
Reorganization 20 Houston 1
Newbenefits 30 Stafford 4
DEPT_LOCATION
Dnumber Dlocation
1 Houston
4 Stafford
5 Bellaire
5 Houston
5 Sugarland
WORKS_ON
Essn Pno Hours
123456789 1 32
123456789 2 7.5
666884444 3 40
435453453 1 20
435453453 2 20
333445555 2 10
333445555 3 10
333445555 10 10
333445555 10 10
333445555 20 10
999887777 30 30
999887777 10 10
987987987 10 35
987987987 30 5
987654321 30 20
987654321 20 15
888665555 20
INSERTING TUPLES INTO DEPENDENT TABLE:
1. INSERT INTO DEPENDENT VALUES(‘333445555’,’Alice’,’F’,’1986-04-05’,’Daughter’)
2. INSERT INTO DEPENDENT VALUES(‘333445555’,’Theodore’,’M’,’1983-10-25’,’Son’)
3. INSERT INTO DEPENDENT VALUES(‘333445555’,’Joy’,’F’,’1958-05-03’,’Spouse’)
4. INSERT INTO DEPENDENT VALUES(‘987654321’,’Abner’,’1942-02-28’,’Spouse’)
5. INSERT INTO DEPENDENT VALUES(‘123456789’,’Michael’,’1988-01-04’,’Son’)
6. INSERT INTO DEPENDENT VALUES(‘123456789’,’Alice’,’F’,’1988-12-30’,’Daughter’)
7. INSERT INTO DEPENDENT VALUES(‘123456789’,’Elizabeth’,’F’,’1967-05-05’,’Spouse’)
DEPENDENT
Essn Dependent_name Sex Bdate Relationship
333445555 Alice F 05-Apr-86 Daughter
333445555 Theodore M 25-Oct-83 Son
333445555 Joy F 03-May-58 Spouse
987654321 Abner M 28-Feb-42 Spouse
123456789 Michael M 04-Jan-88 Son
123456789 Alice F 30-Dec-88 Daughter
123456789 Elizabeth F 05-May-67 Spouse
DELETE COMMAND:
1. DELETE FROM PROJECT
WHERE Pname=’ProductX’
2. DELETE FROM PROJECT
WHERE Pnumber=3
UPDATE COMMAND:
1. UPDATE DEPARTMENT
SET Dname=’Research’
WHERE Dnum=1
PROJECT
Pname Pnumber Plocation Dnum
#Deleted #Deleted
ProductY 2 Sugarland 5
#Deleted #Deleted
Computerization 10 Stafford 4
Reorganisation 20 Houston 1
Newbenefits 30 Stafford 4
DEPARTMENT
Dname Dnumber Mgr_ssn Mgr_start_date
Research 1 888665555 19-Jun-81
Administration 4 987654321 01-Jan-95
Research 5 333445555 22-May-88
Q1. Retrieve the birthdate andaddressof the employeewhose name is‘JohnBSmith’.
SELECT Bdate ,Address
FROM EMPLOYEE
WHERE Fname='john'ANDLname='Smith'
Q2. Retrieve the name andaddressof the all employee whoworkforthe ‘Research’Department.
SELECT Fname ,Minit,Address
FROM EMPLOYEE,DEPARTMENT
WHERE Dname='RESEARCH'AND Dnumber=Dno
Q3.For everyprojectlocatedinthe ‘Stafford’,listthe projectnumber,the controllingdepartment
numberandthe departmentmanagerlastname ,addressandbirthdate.
SELECT Pnumber,Dnum,Lname,Address,Bdate
FROM PROJECT,DEPARTMENT,EMPLOYEE
WHERE project.dnum=department.dnumberand
department.mgr_ssn=employee.ssnand
project.plocation='Stafford'
Q4.For each employeeretrieve the employeefirstandlastname andthe firstand last name of hisor her
immediate supervisior.
SELECT E1.Fname,E1.Lname ,E2.Fname ASSupervisior_Fname,E2.LnameasSupervisior_Lname
FROM EMPLOYEE ASE1,EMPLOYEE AS E2
WHERE E1.super_ssn=E2.ssn
Q1
Bdate Address
09-Jan-65 731 Fondren Houston,TX
Q2
Fname Minit Lname Address
John B Smith 731 FondrenHouston, TX
Franklin T Wong 638 Voss,Houston,TX
Joyce A English 5631 Rice,Houston,TX
Ramesh K Narayan 975,Fire Oak ,Humble,TX
Q3
Pnumber Dnum Lname Address Bdate
10 4 Wallace 291 Berry,Bellaire, TX 20-Jun-41
30 4 Wallace 291 Berry,Bellaire,TX 20-Jun-41
Q4
Fname Lname Supervisior_Fname Supervisior_Lname
John Smith Franklin Wong
Joyce English Franklin Wong
RameshNarayan Franklin Wong
FranklinWong James Borg
JenniferWallace James Borg
Ahmad Jabbar Jennifer Wallace
Alicia Zelaya Jennifer Wallace
Q5.Make a listof the all projectnumberforprojectsthat involve anemployeewhoselastname is
‘Smith’eitherasa workeroras Manager of the departmentthatcontrolsthe projects.
(SELECT DISTINCT Pnumber
FROM PROJECT,DEPARTMENT,EMPLOYEE
WHERE Dnum=Dnumberandmgr_ssn=ssnandLname='Smith')
UNION
(SELECT DISTINCTPnumber
FROM PROJECT,WORKS_ON ,EMPLOYEE
WHERE Pnumber=Pnoand Essn=ssnand Lname='Smith')
Q6.Retrieve all the employeewhose AddressisinHoustonTexas.
SELECT Fname,Minit,Lname,Address
FROM EMPLOYEE
WHERE AddressLike '*Houston*'
Q7.Findall employee whowere bornduring1955’s.
SELECT Fname,Lname,Bdate
FROM EMPLOYEE
WHERE year(bdate)='1955'
Q8.Showthe increasedsalariesif everyemployeeworkingon‘ProductX’projectisgivena10 percent
raise.
SELECT Fname,Minit,Lname,1.1*SalaryasIncreased_Salary
FROM EMPLOYEE,WORKS_ON,PROJECT
WHERE ssn=Essnand Pno=PnumberandPname ='ProductX'
Q9.Retrieve all employee indepartment5whose salaryisb/w $30000 and $40000.
SELECT Fname ,Minit,Lname,Salary
FROM EMPLOYEE
WHERE salarybetween30000 and 40000
Q5
Pnumber
1
2
Q6
Fname Minit Lname Address
John B Smith 731 FondrenHouston,TX
Franklin T Wong 638 Voss,Houston,TX
Joyce A English 5631 Rice, Houston,TX
James E Borg 450 Stone ,Houston,TX
Ahmad V Jabbar 980,Dallas Houston,TX
Q7
Fname Lname Bdate
FranklinWong 08-Dec-55
Q8
Fname Minit Lname Increased_Salary
John B Smith 33000
Q9
Fname Minit Lname Salary
John B Smith 30000
Franklin T Wong 40000
Ramesh K Narayan 38000
Q10.Retrieve the name of the employee andhissalarywhoisearningMaximum.
SELECT MAX(Salary) as[Max_sal]
FROM EMPLOYEE
Q11.Retrieve the salaryof the 2nd
Highestearningemployeeandit’sname.
SELECT Fname,Minit,Lname,salary
FROM EMPLOYEE
WHERE Salary=(SELECTMAX(salary) FROMemployee WHEREsalary<(SELECT MAX(salary) FROM
employee ))
Q12.Retrieve alistof the employeeandthe Projectstheyare workingonorderedbydepartmentand
withindepartmentorderedbythe alphabeticallybylastname thenfirstname.
SELECT Dname ,Lname ,Fname ,Pname
FROM EMPLOYEE,DEPARTMENT,PROJECT,WORKS_ON
WHERE Dnumber=dnoandssn=essnandpno=Pnumber
orderby dname ,Lname,Fname
Q10
Max_sal
55000
Q11
Fname Minit Lname salary
JenniferS Wallace 43000
Q12
Dname Lname Fname Pname
Administration Jabbar Ahmad Newbenefits
Administration Jabbar Ahmad Computerization
Administration Wallace Jennifer Newbenefits
Administration Wallace Jennifer Reorganisation
Administration Zelaya Alicia Newbenefits
Administration Zelaya Alicia Computerization
Headquarters Borg James Reorganisation
Research Narayan Ramesh ProductZ
Research Smith John ProductY
Research Smith John ProductX
Research Wong Franklin Reorganisation
Research Wong Franklin Computerization
Research Wong Franklin Computerization
Research Wong Franklin ProductZ
Research Wong Franklin ProductY

More Related Content

Viewers also liked

To register form_to_oracle_application
To register form_to_oracle_applicationTo register form_to_oracle_application
To register form_to_oracle_applicationAhmed Elshowbkey
 
SQL practice questions for beginners
SQL practice questions for beginnersSQL practice questions for beginners
SQL practice questions for beginners
Mohd Tousif
 
Oracle 10g Forms Lesson 11
Oracle 10g Forms Lesson 11Oracle 10g Forms Lesson 11
Oracle 10g Forms Lesson 11
KAMA3
 
SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...
SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...
SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...
Sean Scott
 
Oracle 10g Forms Lesson 6
Oracle 10g Forms Lesson  6Oracle 10g Forms Lesson  6
Oracle 10g Forms Lesson 6KAMA3
 
10g forms
10g forms10g forms
Oracle 10g Application Server
Oracle 10g Application ServerOracle 10g Application Server
Oracle 10g Application Server
Mark J. Feldman
 
SQL practice questions set - 2
SQL practice questions set - 2SQL practice questions set - 2
SQL practice questions set - 2
Mohd Tousif
 
PLSQL Standards and Best Practices
PLSQL Standards and Best PracticesPLSQL Standards and Best Practices
PLSQL Standards and Best Practices
Alwyn D'Souza
 
Treinamento Oracle Forms
Treinamento Oracle FormsTreinamento Oracle Forms
Treinamento Oracle Forms
Felipe Goulart
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
Smitha Padmanabhan
 
Oracle Form material
Oracle Form materialOracle Form material
Oracle Form material
Rajesh Ch
 
Oracle forms developer 10g vol1
Oracle forms developer 10g vol1Oracle forms developer 10g vol1
Oracle forms developer 10g vol1abdull466
 
SQLcl overview - A new Command Line Interface for Oracle Database
SQLcl overview - A new Command Line Interface for Oracle DatabaseSQLcl overview - A new Command Line Interface for Oracle Database
SQLcl overview - A new Command Line Interface for Oracle Database
Jeff Smith
 
Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)
magupta26
 
Oracle SQL Developer Tips & Tricks
Oracle SQL Developer Tips & TricksOracle SQL Developer Tips & Tricks
Oracle SQL Developer Tips & Tricks
Jeff Smith
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
Dushmanta Nath
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
Parthipan Parthi
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projectsjwjablonski
 

Viewers also liked (20)

To register form_to_oracle_application
To register form_to_oracle_applicationTo register form_to_oracle_application
To register form_to_oracle_application
 
SQL practice questions for beginners
SQL practice questions for beginnersSQL practice questions for beginners
SQL practice questions for beginners
 
Oracle 10g Forms Lesson 11
Oracle 10g Forms Lesson 11Oracle 10g Forms Lesson 11
Oracle 10g Forms Lesson 11
 
SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...
SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...
SQL Patterns in Practice - You're (Probably) Doing it Wrong - Methods for Imp...
 
Oracle 10g Forms Lesson 6
Oracle 10g Forms Lesson  6Oracle 10g Forms Lesson  6
Oracle 10g Forms Lesson 6
 
10g forms
10g forms10g forms
10g forms
 
Oracle 10g Application Server
Oracle 10g Application ServerOracle 10g Application Server
Oracle 10g Application Server
 
SQL practice questions set - 2
SQL practice questions set - 2SQL practice questions set - 2
SQL practice questions set - 2
 
PLSQL Standards and Best Practices
PLSQL Standards and Best PracticesPLSQL Standards and Best Practices
PLSQL Standards and Best Practices
 
Treinamento Oracle Forms
Treinamento Oracle FormsTreinamento Oracle Forms
Treinamento Oracle Forms
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
 
Oracle Form material
Oracle Form materialOracle Form material
Oracle Form material
 
forms builder
forms builderforms builder
forms builder
 
Oracle forms developer 10g vol1
Oracle forms developer 10g vol1Oracle forms developer 10g vol1
Oracle forms developer 10g vol1
 
SQLcl overview - A new Command Line Interface for Oracle Database
SQLcl overview - A new Command Line Interface for Oracle DatabaseSQLcl overview - A new Command Line Interface for Oracle Database
SQLcl overview - A new Command Line Interface for Oracle Database
 
Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)
 
Oracle SQL Developer Tips & Tricks
Oracle SQL Developer Tips & TricksOracle SQL Developer Tips & Tricks
Oracle SQL Developer Tips & Tricks
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
 

Recently uploaded

Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
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
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
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
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
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 ...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
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
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

SQL commands

  • 1. SQL Database and Management System By Manish
  • 3. CREATE COMMAND: 1. EMPLOYEE TABLE: CREATE TABLE EMPLOYEE ( Fname varchar(15) not null, Minitchar, Lname varchar(15) not null, ssn char(9) not null primarykey, Bdate Date, Addressvarchar(30), Sex char, Salarynumber, Super_ssnchar(9) notnull , Dnoint ); 2. DEPARTMENT TABLE: CREATE table department ( Dname varchar(15) not null, DnumberINTegernotnull PRIMARYKEY, mgr_ssn char(9) not null, mrg_start_date date ); 3. DEPT_LOCATION TABLE: CREATE TABLE DEPT_LOCATION ( DnumberintegernotnulL, Dlocationvarchar(15) not null, PRIMARYKEY(Dnumber,Dlocation) );
  • 4. 4. WORKS_ON TABLE: CREATE TABLE WORKS_ON ( Essnchar(9) not null, PnoINt, hoursnumber, PRIMARYKEY(ESSN,PNO) ); 5. PROJECT TABLE: CREATE TABLE PROJECT ( Pname varchar(10) not null, PnumberINTnotnull PRIMARY KEY, Plocationvarchar(15), DmunINT ); 6. DEPENDENT TABLE: CREATE TABLE DEPENDENT ( Essn char(9) notnull, Dependent_namevarchar(15) notnull PRIMARY KEY, Sex char , Bdate time, Relationshipvarchar(10) );
  • 5. INSERT COMMAND: INSERTING TUPLES INTO EMPLOYEE TABLE: 1. INSERT INTO EMPLOYEE VALUES (‘John’,’B’,’Smith’,’123456789’,’1965-01-09’,’731 Fondren, Houston, TX’,’M’,30000,333445555,5) 2. INSERT INTO EMPLOYEE VALUES (‘Franklin’,’T’,’Wong’,333445555’,’1955-13-08’,’638 Voss,Houston, TX’,’M’,40000,888665555,5) 3. INSERT INTO EMPLOYEE VALUES (‘Alicia’,’J’,’Zelaya’,’999887777’,’1968-01-19’,’3321 Castle,Spring, TX’,’F’,25000,987654321,4) 4. INSERT INTO EMPLOYEE VALUES (‘Jennifer’,’S’,’Wallace’,’987654321’,’1941-06-20’,’291 Berry,Bellaire, TX’,’F’,43000,888665555,4) 5. INSERT INTO EMPLOYEE VALUES (‘Ramesh’,’K’,’Narayan’,’666884444’,’1962-09-15’,’975 FireOak, Humble, TX’,’M’,38000,333445555,5) 6. INSERT INTO EMPLOYEE VALUES (‘Joyce’,’A’,’English’,’453453453’,’1972-07-31’,’5631 Rice ,Houston,TX’,’F’,25000,333445555,5) 7. INSERT INTO EMPLOYEE VALUES (‘Ahmed’,’V’,’Jabbar’,’987987987’,’1969-03-29’,’980 Dallas,Houston, TX’,’M’,25000,987654321,4) 8. INSERT INTO EMPLOYEE VALUES (‘James’,’E’,’Borg’,’888665555’,’1937-11-10’,’450 Stone, Houston, TX’,’M’,55000,NULL,1) EMPLOYEE Fname Minit Lname Ssn Bdate Address Sex Salary Super_ssn Dno Ahmad V Jabbar 987987987 29-Mar-69 980,Dallas Houstontx M 25000 987654321 4 Alicia J Zelaya 999887777 19-Jan-68 3321 castle,springtx F 25000 987654321 4 FranklinT Wong 333445555 08-Dec-55 638 voss,Houstontx M 40000 888665555 5 James E Borg 888665555 10-Nov-37 450 Stone ,Houstontx M 55000 1 JenniferS Wallace 987654321 20-Jun-41 291 berry,Bellaire,tx F 43000 888665555 4 John B Smith 123456789 09-Jan-65 731 Fondren,Houston,TX M 30000 333445555 5 Joyce A English 453453453 31-Jul-72 5631 Rice,Houstontx F 25000 333445555 5 RameshK Narayan 666884444 15-Sep-62 975,Fire Oak ,Humble,tx M 38000 333445555 5 INSERTING TUPLES INTO DEPARTMENT TABLE: 1. INSERT INTO DEPARTMENT VALUES (‘Research’,5,333445555,’1988-05-22’) 2. INSERT INTO DEPARTMENT VALUES (‘Administration’,4,987654321,’1995-01-01’) 3. INSERT INTO DEPARTMENT VALUES (‘Headquarters’1,888665555,’1981-06-19’) DEPARTMENT Dname Dnumber Mgr_ssn Mgr_start_date RESEARCH 1 888665555 19-Jun-81 Administration 4 987654321 01-Jan-95 Research 5 333445555 22-May-88
  • 6. INSERTING TUPLES INTO DEPT_LOCATIONS TABLE: 1. INSERT INTO DEPT_LOCATIONS VALUES (1,’Houston’) 2. INSERT INTO DEPT_LOCATIONS VALUES (4,’Stafford’) 3. INSERT INTO DEPT_LOCATIONS VALUES (5,’Bellaire’) 4. INSERT INTO DEPT_LOCATIONS VALUES (5,’Sugarland’) 5. INSERT INTO DEPT_LOCATIONS VALUES (5,’Houston’) INSERTING TUPLES INTO WORKS_ON TABLE: 1. INSERT INTO WORKS_ON VALUES(123456789,1,32.5) 2. INSERT INTO WORKS_ON VALUES(123456789,2,7.5) 3. INSERT INTO WORKS_ON VALUES(666884444,3,40.0) 4. INSERT INTO WORKS_ON VALUES(453453453,1,20.0) 5. INSERT INTO WORKS_ON VALUES(453453453,2,20.0) 6. INSERT INTO WORKS_ON VALUES(333445555,2,10.0) 7. INSERT INTO WORKS_ON VALUES(333445555,3,10.0) 8. INSERT INTO WORKS_ON VALUES(333445555,10,10.0) 9. INSERT INTO WORKS_ON VALUES(333445555,20,10.0) 10. INSERT INTO WORKS_ON VALUES(999887777,30,30.0) 11. INSERT INTO WORKS_ON VALUES(999887777,10,10.0) 12. INSERT INTO WORKS_ON VALUES(987987987,10,10.0) 13. INSERT INTO WORKS_ON VALUES(987987987,30,5.0) 14. INSERT INTO WORKS_ON VALUES(987654321,30,20.0) 15. INSERT INTO WORKS_ON VALUES(987654321,20,15.0) 16. INSERT INTO WORKS_ON VALUES(888665555,20,NULL) INSERTING TUPLES INTO PROJECT TABLE: 1. INSERT INTO PROJECT VALUES(‘ProductX’,1,’Bellaire’,5) 2. INSERT INTO PROJECT VALUES(‘ProductY’,2,’Sugarland’,5) 3. INSERT INTO PROJECT VALUES(‘ProductZ’,3,’Houston’,5) 4. INSERT INTO PROJECT VALUES(‘Computerization’,10,’Stafford’,4) 5. INSERT INTO PROJECT VALUES(‘Reorganization’,20,’Houston’,1) 6. INSERT INTO PROJECT VALUES(‘Newbenefits’30,’Stafford’,4) PROJECT Pname Pnumber Plocation Dnum ProductX 1 Bellaire 5 ProductY 2 Sugarland 5 ProductZ 3 Houston 5 Computerization 10 Stafford 4 Reorganization 20 Houston 1 Newbenefits 30 Stafford 4 DEPT_LOCATION Dnumber Dlocation 1 Houston 4 Stafford 5 Bellaire 5 Houston 5 Sugarland WORKS_ON Essn Pno Hours 123456789 1 32 123456789 2 7.5 666884444 3 40 435453453 1 20 435453453 2 20 333445555 2 10 333445555 3 10 333445555 10 10 333445555 10 10 333445555 20 10 999887777 30 30 999887777 10 10 987987987 10 35 987987987 30 5 987654321 30 20 987654321 20 15 888665555 20
  • 7. INSERTING TUPLES INTO DEPENDENT TABLE: 1. INSERT INTO DEPENDENT VALUES(‘333445555’,’Alice’,’F’,’1986-04-05’,’Daughter’) 2. INSERT INTO DEPENDENT VALUES(‘333445555’,’Theodore’,’M’,’1983-10-25’,’Son’) 3. INSERT INTO DEPENDENT VALUES(‘333445555’,’Joy’,’F’,’1958-05-03’,’Spouse’) 4. INSERT INTO DEPENDENT VALUES(‘987654321’,’Abner’,’1942-02-28’,’Spouse’) 5. INSERT INTO DEPENDENT VALUES(‘123456789’,’Michael’,’1988-01-04’,’Son’) 6. INSERT INTO DEPENDENT VALUES(‘123456789’,’Alice’,’F’,’1988-12-30’,’Daughter’) 7. INSERT INTO DEPENDENT VALUES(‘123456789’,’Elizabeth’,’F’,’1967-05-05’,’Spouse’) DEPENDENT Essn Dependent_name Sex Bdate Relationship 333445555 Alice F 05-Apr-86 Daughter 333445555 Theodore M 25-Oct-83 Son 333445555 Joy F 03-May-58 Spouse 987654321 Abner M 28-Feb-42 Spouse 123456789 Michael M 04-Jan-88 Son 123456789 Alice F 30-Dec-88 Daughter 123456789 Elizabeth F 05-May-67 Spouse DELETE COMMAND: 1. DELETE FROM PROJECT WHERE Pname=’ProductX’ 2. DELETE FROM PROJECT WHERE Pnumber=3 UPDATE COMMAND: 1. UPDATE DEPARTMENT SET Dname=’Research’ WHERE Dnum=1 PROJECT Pname Pnumber Plocation Dnum #Deleted #Deleted ProductY 2 Sugarland 5 #Deleted #Deleted Computerization 10 Stafford 4 Reorganisation 20 Houston 1 Newbenefits 30 Stafford 4 DEPARTMENT Dname Dnumber Mgr_ssn Mgr_start_date Research 1 888665555 19-Jun-81 Administration 4 987654321 01-Jan-95 Research 5 333445555 22-May-88
  • 8. Q1. Retrieve the birthdate andaddressof the employeewhose name is‘JohnBSmith’. SELECT Bdate ,Address FROM EMPLOYEE WHERE Fname='john'ANDLname='Smith' Q2. Retrieve the name andaddressof the all employee whoworkforthe ‘Research’Department. SELECT Fname ,Minit,Address FROM EMPLOYEE,DEPARTMENT WHERE Dname='RESEARCH'AND Dnumber=Dno Q3.For everyprojectlocatedinthe ‘Stafford’,listthe projectnumber,the controllingdepartment numberandthe departmentmanagerlastname ,addressandbirthdate. SELECT Pnumber,Dnum,Lname,Address,Bdate FROM PROJECT,DEPARTMENT,EMPLOYEE WHERE project.dnum=department.dnumberand department.mgr_ssn=employee.ssnand project.plocation='Stafford' Q4.For each employeeretrieve the employeefirstandlastname andthe firstand last name of hisor her immediate supervisior. SELECT E1.Fname,E1.Lname ,E2.Fname ASSupervisior_Fname,E2.LnameasSupervisior_Lname FROM EMPLOYEE ASE1,EMPLOYEE AS E2 WHERE E1.super_ssn=E2.ssn Q1 Bdate Address 09-Jan-65 731 Fondren Houston,TX Q2 Fname Minit Lname Address John B Smith 731 FondrenHouston, TX Franklin T Wong 638 Voss,Houston,TX Joyce A English 5631 Rice,Houston,TX Ramesh K Narayan 975,Fire Oak ,Humble,TX Q3 Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry,Bellaire, TX 20-Jun-41 30 4 Wallace 291 Berry,Bellaire,TX 20-Jun-41 Q4 Fname Lname Supervisior_Fname Supervisior_Lname John Smith Franklin Wong Joyce English Franklin Wong RameshNarayan Franklin Wong FranklinWong James Borg JenniferWallace James Borg Ahmad Jabbar Jennifer Wallace Alicia Zelaya Jennifer Wallace
  • 9. Q5.Make a listof the all projectnumberforprojectsthat involve anemployeewhoselastname is ‘Smith’eitherasa workeroras Manager of the departmentthatcontrolsthe projects. (SELECT DISTINCT Pnumber FROM PROJECT,DEPARTMENT,EMPLOYEE WHERE Dnum=Dnumberandmgr_ssn=ssnandLname='Smith') UNION (SELECT DISTINCTPnumber FROM PROJECT,WORKS_ON ,EMPLOYEE WHERE Pnumber=Pnoand Essn=ssnand Lname='Smith') Q6.Retrieve all the employeewhose AddressisinHoustonTexas. SELECT Fname,Minit,Lname,Address FROM EMPLOYEE WHERE AddressLike '*Houston*' Q7.Findall employee whowere bornduring1955’s. SELECT Fname,Lname,Bdate FROM EMPLOYEE WHERE year(bdate)='1955' Q8.Showthe increasedsalariesif everyemployeeworkingon‘ProductX’projectisgivena10 percent raise. SELECT Fname,Minit,Lname,1.1*SalaryasIncreased_Salary FROM EMPLOYEE,WORKS_ON,PROJECT WHERE ssn=Essnand Pno=PnumberandPname ='ProductX' Q9.Retrieve all employee indepartment5whose salaryisb/w $30000 and $40000. SELECT Fname ,Minit,Lname,Salary FROM EMPLOYEE WHERE salarybetween30000 and 40000 Q5 Pnumber 1 2 Q6 Fname Minit Lname Address John B Smith 731 FondrenHouston,TX Franklin T Wong 638 Voss,Houston,TX Joyce A English 5631 Rice, Houston,TX James E Borg 450 Stone ,Houston,TX Ahmad V Jabbar 980,Dallas Houston,TX Q7 Fname Lname Bdate FranklinWong 08-Dec-55 Q8 Fname Minit Lname Increased_Salary John B Smith 33000 Q9 Fname Minit Lname Salary John B Smith 30000 Franklin T Wong 40000 Ramesh K Narayan 38000
  • 10. Q10.Retrieve the name of the employee andhissalarywhoisearningMaximum. SELECT MAX(Salary) as[Max_sal] FROM EMPLOYEE Q11.Retrieve the salaryof the 2nd Highestearningemployeeandit’sname. SELECT Fname,Minit,Lname,salary FROM EMPLOYEE WHERE Salary=(SELECTMAX(salary) FROMemployee WHEREsalary<(SELECT MAX(salary) FROM employee )) Q12.Retrieve alistof the employeeandthe Projectstheyare workingonorderedbydepartmentand withindepartmentorderedbythe alphabeticallybylastname thenfirstname. SELECT Dname ,Lname ,Fname ,Pname FROM EMPLOYEE,DEPARTMENT,PROJECT,WORKS_ON WHERE Dnumber=dnoandssn=essnandpno=Pnumber orderby dname ,Lname,Fname Q10 Max_sal 55000 Q11 Fname Minit Lname salary JenniferS Wallace 43000 Q12 Dname Lname Fname Pname Administration Jabbar Ahmad Newbenefits Administration Jabbar Ahmad Computerization Administration Wallace Jennifer Newbenefits Administration Wallace Jennifer Reorganisation Administration Zelaya Alicia Newbenefits Administration Zelaya Alicia Computerization Headquarters Borg James Reorganisation Research Narayan Ramesh ProductZ Research Smith John ProductY Research Smith John ProductX Research Wong Franklin Reorganisation Research Wong Franklin Computerization Research Wong Franklin Computerization Research Wong Franklin ProductZ Research Wong Franklin ProductY