Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL 5 (Assignment)

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7
At a glance
Powered by AI
SQL is used to manage and query data in a relational database. Key SQL statements are used to select, insert, update and delete data.

SQL is used to manage data in relational database systems. It allows users to define, manipulate, and query data in a database.

The INSERT statement is used to insert new records into a table. The UPDATE statement is used to modify existing records in a table. The DELETE statement is used to remove records from a table.

SQL Assignment

1. What does SQL stand for?


Structured Question Language
Structured Query Language
Strong Question Language

2. Which SQL statement is used to extract data from a database?

OPEN
GET
EXTRACT
SELECT

3. Which SQL statement is used to update data in a database?

SAVE
UPDATE
MODIFY
SAVE AS

4. Which SQL statement is used to delete data from a database?

REMOVE
DELETE
COLLAPSE

5. Which SQL statement is used to insert new data in a database?

ADD NEW
INSERT INTO
ADD RECORD
INSERT NEW
6. With SQL, how do you select a column named "FirstName" from a table named
"Persons"?

EXTRACT FirstName FROM Persons


SELECT Persons.FirstName
SELECT FirstName FROM Persons

7. With SQL, how do you select all the columns from a table named "Persons"?

SELECT Persons
SELECT [all] FROM Persons
SELECT *.Persons
SELECT * FROM Persons

8. With SQL, how do you select all the records from a table named "Persons" where
the value of the column "FirstName" is "Peter"?

SELECT * FROM Persons WHERE FirstName='Peter'


SELECT [all] FROM Persons WHERE FirstName='Peter'
SELECT * FROM Persons WHERE FirstName LIKE 'Peter'
SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'

9. With SQL, how do you select all the records from a table named "Persons" where
the value of the column "FirstName" starts with an "a"?

SELECT * FROM Persons WHERE FirstName='%a%'


SELECT * FROM Persons WHERE FirstName='a'
SELECT * FROM Persons WHERE FirstName LIKE '%a'
SELECT * FROM Persons WHERE FirstName LIKE 'a%'

10. The OR operator displays a record if ANY conditions listed are true. The AND
operator displays a record if ALL of the conditions listed are true

False
True
12. With SQL, how do you select all the records from a table named "Persons"
where the "LastName" is alphabetically between (and including) "Hansen" and
"Pettersen"?

SELECT * FROM Persons WHERE LastName>'Hansen' AND


LastName<'Pettersen'
SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND
'Pettersen'
SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons

13. Which SQL statement is used to return only


different values?

SELECT UNIQUE
SELECT DIFFERENT
SELECT DISTINCT
14. Which SQL keyword is used to sort the result-set?

SORT
SORT BY
ORDER BY
ORDER
15. With SQL, how can you return all the records from a table named "Persons"
sorted descending by "FirstName"?

SELECT * FROM Persons ORDER BY FirstName DESC


SELECT * FROM Persons ORDER FirstName DESC
SELECT * FROM Persons SORT BY 'FirstName' DESC
SELECT * FROM Persons SORT 'FirstName' DESC
16. With SQL, how can you insert a new record into the "Persons" table?

INSERT VALUES ('Jimmy', 'Jackson') INTO Persons


INSERT ('Jimmy', 'Jackson') INTO Persons
INSERT INTO Persons VALUES ('Jimmy', 'Jackson')
.

17. With SQL, how can you insert "Olsen" as the "LastName" in the "Persons"
table?

INSERT INTO Persons ('Olsen') INTO LastName


INSERT INTO Persons (LastName) VALUES ('Olsen')
INSERT ('Olsen') INTO Persons (LastName)
18. How can you change "Hansen" into "Nilsen" in the "LastName" column in the
Persons table?

UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'


MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'
19. With SQL, how can you delete the records where the "FirstName" is "Peter" in
the Persons Table?

DELETE FirstName='Peter' FROM Persons


DELETE FROM Persons WHERE FirstName = 'Peter'
DELETE ROW FirstName='Peter' FROM Persons
20. With SQL, how can you return the number of records in the "Persons" table?

SELECT COLUMNS() FROM Persons


SELECT COUNT() FROM Persons
SELECT COLUMNS(*) FROM Persons
SELECT COUNT(*) FROM Persons
.

Theoritical Questions:

What is SQL and where does it come from?


What are the difference between DDL, DML and DCL commands?
How does one escape characters when building SQL queries?
How does one eliminate duplicate rows from a table?
How does one generate primary key values for a table?
How does one get the time difference between two date columns?
How does one add a day/hour/minute/second to a date value?
How does one count different data values in a column?
How does one count/sum RANGES of data values in a column?
Can one retrieve only the Nth row from a table?
Can one retrieve only rows X to Y from a table?
How does one select EVERY Nth row from a table?
How does one select the TOP N rows from a table?
How does one code a tree-structured query?
How does one code a matrix report in SQL?
How does one implement IF-THEN-ELSE in a select statement?
How can one dump/ examine the exact content of a database column?
Can one drop a column from a table?
Can one rename a column in a table?
How does one find the next value of a sequence?

Queries:
Dept

Deptno Dname Loc


10 ACCOUNT Mumbai
20 ADMIN Banglore
30 IT Chennai

Emp

Empno Ename Job Salary Comm Hiredate Deptno Experience


11999 SCOTT MANAGER 45000 0 12-Jan-00 10 20
12000 BLACK ACCOUNTANT 20000 1500 13-Feb-00 10 13
12001 SMITH ASS ACCOUNTANT 15000 1200 24-Jan-00 10 7
12002 KING OPERATOR 8000 1200 15-Mar-00 20 1
12003 RED SN OPERATOR 10000 0 16-Apr-00 20 2
12004 KAT SOFTWARE ENGINEER 35000 0 17-Nov-00 30 3
ASS SOFTARE 2
12005 MICHLE ENGINEER 25000 0 18-Jan-00 30
DATA ENTRY 1
12006 MAKD OPERATOR 9000 0 1-Jan-00 20

SQL
Level –1

1)Write a query to list all the employees who are working as clerk
2) Write a query to list the employees who are working as clerks or
managers with the minimum salary of 4000
3) Write a query to get the current date
4) Write a query o list the employees who are having experience more
than 4 years
5) Write a query to list the employees who hired in the last seven days
6) Write a query to list the employees whose salaries are within the
range of 5000 and 10000
7) Write a query to list the employees who have joined in the month of
March’99
8) Write a query to list the employees whose salaries are not within
the range of 10000 and 13000
9) Write a query who are getting 1000, 2000, 3000
10) Query to list all employees except who are joined on 11- Sep-2001,
31-Mar-2002
11) To list all the employees whose names are having ‘O’ as second
character

12) To list all the employees whose names are having ‘R’ as last
character
13) To list all the employees whose names are having just 5 characters
as length.
14) To list all the employees whose names are starting with ‘R’ and
ending with ‘O’

Write The Following Queries For The Above Tables:


A) Display the all records of the employee’s table.
B) Display the employee name, salary, and commission of those
Employee’s salaries Higher than 1500.
C) Display the employee name, salary, job and commission of
those
Employee’s commission is null.
D) Display the employee’s name, employee number, salary, job
and
Commission Of that Employee’s salary higher than Scott’s
salary.
E) Write inner-joining Query.
F) Write the Outer-joining Query.
G) Display Department name, location and employee name of
those
Employee’s who work in Account Department.
H) Display name, job, salary of those employees who is
salary’s 1rd
highest
I) Display name, job, salary of those employees who is
salary’s 1rd lowest
Salary among all employees’ salaries.
J) Display name, job,salary of those employees who work Mr.KAT
Employee.
K) Display name,job,salary of those employee who is not work
with Mr. KAT
L) Display the Department name, employee name and salary from
emplyee
tables.
M) Show the sum of salaries of all department but sum of
salary must be
Greater than 8500.
N) Write the query display the Department names and their
employee’s
names.
O) Display the all employees name, job and salary they work in
department 10.
P) Display the all records their salaries must be higher than
Clerk
Salaries.
Q) Show the records of the all employees their last letter’ H
in the
name.
R) Sum salaries of the all employees according to the job.
S) Increase the 10% of Salary who work in Account Department.
T) Delete the all employee who work in the Scott Department.
U) Assign the scott salary who work in the department 10.
V) Delete the all records their salaries higher than 1500;
W) Display the highest salary and his name from employee
table.
X) splay the Lowest salary and his name from employee table.
Y) Display the highest salary from Account Department.
Z) Display the lowest salary from Account Department.
AA) Assign the highest salary to the scott employee.
AB) Assign the lowest salary the the scott employee.
AC) Assign the 10 % of salary to every employee of commission.
AD) Display the all records their commission is null.

You might also like