SQL statements Flashcards

1
Q

1.Create a new database called ADTelecom.

A

CREATE DATABASE ADTelecom;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2.Use the database that you have created (ADTelecom).

A

USE ADTelecom;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

3.Create a table in the database named Companystaff.

A

CREATE TABLE Companystaff (
CustomerID varchar(60),
FirstName varchar(60),
LastName varchar(60),
City varchar(255),
Sex char(1),
Department varchar(60),
Salary int
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

4.Show the table created within the database.

A

SHOW TABLES;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

5.Display the structure of the table Companystaff.

A

DESCRIBE Companystaff;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

6.Populate the table Companystaff by inserting the values listed below.

A

INSERT INTO Companystaff
VALUES (‘86-192’, ‘John’, ‘Hayes’, ‘Palo Alto’, ‘M’, ‘Operations’, 127000),
(‘28-019’, ‘Elizabeth’, ‘McFarlane’, ‘Rye’, ‘F’, ‘Support’, 73000),
(‘89-677’, ‘Kenneth’, ‘Johnson’, ‘Stamford’, ‘M’, ‘Analytics’, 97000),
(‘73-128’, ‘Michael’, ‘Smith’, ‘Harrison’, ‘M’, ‘Analytics’, 94000), (‘12-321’, ‘William’, ‘Hayes’, ‘Pittsfield’, ‘M’, ‘Sales’, 105000),
(‘66-336’, ‘Rose’, ‘Turner’, ‘Harrison’, ‘F’, ‘Operations’, 115000),
(‘28-019’, ‘Judy’, ‘Lindsay’, ‘Rye’, ‘F’, ‘Support’, 68000);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

7.Retrieve all the records from the Companystaff table.

A

SELECT * FROM Companystaff;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

8.Retrieve all the values for columns FirstName, LastName, and Salary from Companystaff table.

A

SELECT FirstName, LastName, Salary FROM Companystaff;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

9.Retrieve a record from the Companystaff table whose last name is ‘Hayes’.

A

SELECT * FROM Companystaff WHERE LastName=’Hayes’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

10.Retrieve Firstname, Lastname, Department from the Companystaff table with Department ‘Operations’.

A

SELECT FirstName, LastName, Department FROM Companystaff WHERE Department=’Operations’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

11.Retrieve Firstname, Lastname, Sex, Salary from the Companystaff table with Sex ‘M’ AND Salary greater than 100000.

A

SELECT FirstName, LastName, Sex, Salary FROM Companystaff WHERE Sex=’M’ AND Salary>100000;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

12.Retrieve Firstname, Lastname, City, Salary from the Companystaff table with City ‘Harrison’ OR Salary less than or equal to 105000.

A

SELECT FirstName, LastName, City, Salary FROM Companystaff WHERE City=’Harrison’ OR Salary<=105000;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

13.Retrieve Firstname, Lastname, Salary from the Companystaff table and store the result in a new column called IncreasedSalary when each salary is added with 5000.

A

SELECT FirstName, LastName, Salary, (Salary + 5000) AS IncreasedSalary FROM Companystaff;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

14.Display all records from the Companystaff table in ascending order by Lastname.

A

SELECT * FROM Companystaff ORDER BY LastName ASC;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

15.Display all the records from Companystaff in descending order by Salary.

A

SELECT * FROM Companystaff ORDER BY Salary DESC;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly