Docsity

DATA MANAGEMENT APPLICATIONS D427 MYSQL SQL PROGRAMING INTERMEDIATE LEVEL UPDATED ACTUAL Q, Exams of Database Management Systems (DBMS)

Toggle sidebar
bg1
DA
T
A
M
A
N
AGE
M
E
NT
A
PPL
ICA
T
I
ONS
D
427
MYSQL
SQL
PRO
G
R
A
M
I
N
G
I
NT
E
RM
EDIA
T
E
L
E
V
E
L
UP
DA
T
ED
AC
TU
A
L
QU
E
ST
I
ONS
W
I
T
H
C
ORR
EC
T
A
NSW
E
RS
Q
u
e
st
i
on
1.
T
he
M
e
m
be
r
t
a
ble
w
ill
h
a
v
e
t
he
f
o
ll
ow
i
n
g
c
o
l
umns
:
ID
—
pos
i
t
i
v
e
i
nt
ege
r
F
i
rst
Na
m
e
—
v
a
r
i
a
ble
-
le
n
g
t
h
str
i
n
g
w
i
t
h
up
to
100
ch
a
r
a
c
t
e
rs
,
M
iddle
I
n
i
t
i
a
l
—
fi
x
ed
-
le
n
g
t
h
str
i
n
g
w
i
t
h
1
ch
a
r
a
c
t
e
r
,
La
st
Na
m
e
—
v
a
r
i
a
ble
-
le
n
g
t
h
str
i
n
g
w
i
t
h
up
to
100
ch
a
r
a
c
t
e
rs
,
D
a
t
e
O
f
B
i
rt
h
—
d
a
t
e
,
A
nnu
a
l
P
ledge
—
pos
i
t
i
v
e
deci
m
a
l
v
a
l
u
e
r
e
pr
e
s
e
nt
i
n
g
a
c
ost
o
f
up
to
$999,999,
w
i
t
h
2
digi
ts
f
or
ce
nts
,
W
r
i
t
e
a
SQL
st
a
t
e
m
e
nt
to
c
r
e
a
t
e
t
he
M
e
m
be
r
t
a
ble
.
D
o
not
a
dd
a
ny
a
ddi
t
i
on
a
l
c
onstr
a
i
nts
to
a
ny
c
o
l
umn
be
yon
d
w
h
a
t
i
s
st
a
t
ed
.
A
NSW
E
R
C
R
EA
T
E
T
AB
L
E
M
e
m
be
r

ID
I
NT
PR
I
M
A
RY
K
E
Y
uns
ig
n
ed
,
F
i
rst
Na
m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
i
n
g
C
o
de
)
);
1
/
33
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21

Partial preview of the text

Download DATA MANAGEMENT APPLICATIONS D427 MYSQL SQL PROGRAMING INTERMEDIATE LEVEL UPDATED ACTUAL Q and more Exams Database Management Systems (DBMS) in PDF only on Docsity!

DATA MANAGEMENT APPLICATIONS D 427 MYSQL

SQL PROGRAMING INTERMEDIATE LEVEL UPDATED

ACTUAL QUESTIONS WITH CORRECT ANSWERS

Question 1.

The Member table will have the following columns: ID—positive integer FirstName—variable-length string with up to 100 characters, MiddleInitial—fixed-length string with 1 character, LastName—variable-length string with up to 100 characters, DateOfBirth—date, AnnualPledge—positive decimal value representing a cost of up to $999,999, with 2 digits for cents, Write a SQL statement to create the Member table. Do not add any additional constraints to any column beyond what is stated.

ANSWER CREATE TABLE Member  ID INT PRIMARY KEY unsigned, FirstName VARCHAR 100 ī‚‚, MiddleInitial CHAR 1 ī‚‚, LastName VARCHAR 100 ī‚‚, DateOfBirth DATE, AnnualPledge DECIMAL8, 2 ī‚‚ unsigned );

Question 2.

The Rating table has the following columns: RatingCode—variable-length string, primary key, RatingDescription—variable-length string, The Movie table should have the following columns: Title—variable-length string, maximum 30 characters, RatingCode—variable-length string, maximum 5 characters, Write a SQL statement to create the Movie table. Designate the RatingCode column in the Movie table as a foreign key to the RatingCode column in the Rating table.

ANSWER CREATE TABLE Movie  Title VARCHAR 30 ī‚‚, RatingCode VARCHAR 5 ī‚‚, FOREIGN KEY (RatingCode) REFERENCES Rating(RatingCode) );

The Movie table has the following columns: ID—integer, primary key, Title—variable-length string, Genre—variable-length string, RatingCode—variable-length string, Year—integer, A new column must be added to the Movie table: Column name: Score, Data type: decimal(3,1), Write a SQL statement to add the Score column to the Movie table.

ANSWER ALTER TABLE Movie ADD Score DECIMAL3, 1 ī‚‚;

Question 4.

The Movie table has the following columns: ID—integer, primary key, Title—variable-length string, Genre—variable-length string, RatingCode—variable-length string, Year—integer, Write a SQL statement to create a view named MyMovies that contains the Title, Genre, and Year columns for all movies. Ensure your result set returns the columns in the order indicated.

ANSWER CREATE VIEW MyMovies AS SELECT Title, Genre, Year FROM Movie;

Question 5.

The Movie table has the following columns: ID—integer, Title—variable-length string, Genre—variable-length string, RatingCode—variable-length string, Year—integer, Write a SQL statement to modify the Movie table to make the ID column the primary key.

ANSWER ALTER TABLE Movie ADD PRIMARY KEY IDī‚‚;

The Movie table has the following columns: ID—integer, primary key, Title—variable-length string, Genre—variable-length string, RatingCode—variable-length string, Year—integer, Write a SQL statement to delete the row with the ID value of 3 from the Movie table.

ANSWER DELETE FROM Movie WHERE ID ī‚› 3;

Question 10.

The Movie table has the following columns: ID—integer, primary key, Title—variable-length string, Genre—variable-length string, RatingCode—variable-length string, Year—integer, Write a SQL query to display all Title values in alphabetical order Aī‚ˆZ.

ANSWER SELECT Title FROM Movie ORDER BY Title ASC;

Question 11.

The Movie table has the following columns: ID—integer, primary key, Title—variable-length string, Genre—variable-length string, RatingCode—variable-length string, Year—integer, Write a SQL query to return how many movies have a Year value of 2019.

ANSWER SELECT COUNT*ī‚‚ AS MovieCount FROM Movie WHERE Year ī‚› 2019;

The Movie table has the following columns: ID ī‚ˆ integer, primary key, Title - variable-length string, Genre - variable-length string, RatingCode - variable-length string, Year - integer, The YearStats table has the following columns: Year - integer, TotalGross - bigint unsigned, Releases - integer, Write a SQL query to display both the Title and the TotalGross (if available) for all movies. Ensure your result set returns the columns in the order indicated.

ANSWER SELECT Movie.Title, YearStats.TotalGross FROM Movie LEFT JOIN YearStats ON Movie.Year = YearStats.Year;

Question 13.

San Francisco, CA 94110 USA , How many attributes are present in the address fragment?

ANSWER 4 Attributes

Question 14.

The Package table has the following columns: Weight—decimal, Description—optional variable length string, LastChangedDate—date, TrackingNumber—integer, Which column should be designated the primary key for the Package table?

ANSWER TrackingNumber

Question 15.

Which data type will store "2022ī‚ˆ 01 ī‚ˆ 10 14 ī‚’ 22 ī‚’12" as a temporal value without loss of information?

ANSWER DATETIME

Define a UPDATE statement?

ANSWER UPDATE table_name SET column 1 ī‚› value1, column 2 ī‚› value2, ... WHERE condition;

Question 23.

Define a DELETE statement?

ANSWER DELETE FROM table_name WHERE condition;

Question 24.

The Book table has the following columns: genre - varchar(20), pages - integer, author_id - char(3), isbn_number - varchar(20), Which column should be designated at the primary key for the Book table?

ANSWER isbn_number

Question 25.

The Book table has the following columns: genre - varchar(20), pages - integer, author_id - char(3), isbn_number - varchar(20), Which column should be designated as the foreign key for the Book table?

ANSWER author_id

Which data type represents numbers with fractional values:

ANSWER DECIMAL

Question 27.

Which of the following is a DML command?

ANSWER INSERT, DELETE, UPDATE

Question 28.

CREATE TABLE Invoice ( invoice_id INT NOT NULL AUTO_INCREMENT, date DATE NOT NULL, customer_id INT NOT NULL, PRIMARY KEY (invoice_id), FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE CASCADE ); Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with foreign key reference statement above, what would happen to invoices in the Invoice table that are linked to a customer if that customer is deleted.

ANSWER Those invoices would be deleted also.

The Customer table will have the following columns: CustomerID—positive integer, FirstName— variable-length string with up to 50 characters, MiddleInitial—fixed-length string with 1 character, LastName—variable-length string with up to 50 characters, DateOfBirth—date, CreditLimit—positive decimal value representing a cost of up to $19,999, with 2 digits for cents, Write a SQL statement to create the Customer table. Do not add any additional constraints to any column beyond what is stated.

ANSWER CREATE TABLE Customer  CustomerID INT UNSIGNED, FirstName VARCHAR 50 ī‚‚, MiddleInitial CHAR 1 ī‚‚, LastName VARCHAR 50 ī‚‚, DateOfBirth DATE, CreditLimit DECIMAL7,2ī‚‚ UNSIGNED );

Question 33.

The Genre table has the following columns: GenreCode—variable-length string, primary key, GenreDescription—variable-length string, The Book table should have the following columns: Title—variable-length string, maximum 30 characters, GenreCode—variable-length string, maximum 5 characters, Write a SQL statement to create the Book table. Designate the GenreCode column in the Book table as a foreign key to the GenreCode column in the Genre table.

ANSWER CREATE TABLE Book ( Title VARCHAR 30 ī‚‚, GenreCode VARCHAR 5 ī‚‚, FOREIGN KEY GenreCode) REFERENCES Genre(GenreCode) );

The Automobile table has the following columns: ID—integer, primary key, Make—variable-length string, Model—variable-length string, Year—integer, A new column must be added to the Automobile table: Column name: SafetyRating, Data type: decimal(3,1), Write a SQL statement to add the SafetyRating column to the Automobile table.

ANSWER ALTER TABLE Automobile ADD SafetyRating DECIMAL3,1ī‚‚;

Question 35.

The Book table has the following columns: ID—integer, primary key, Title—variable-length string, Genre—variable-length string, Year—integer, Write a SQL statement to create a view named My-Books that contains the Title, Genre, and Year columns for all movies books. Ensure your result set returns the columns in the order indicated.

ANSWER CREATE VIEW MyBooks AS SELECT Title, Genre, Year FROM Book;

Question 36.

A database has a view named BookView. Write a SQL statement to delete the view named BookView from the database.

ANSWER DROP VIEW BookView;

The Book table has the following columns: ID—integer, primary key, auto_increment Title—variable- length string, Genre—variable-length string, Year—integer, The following data needs to be added to the Book table: Title Genre Year, The Joy Luck Club, Fiction, 1989, Write a SQL statement to insert the indicated data into the Book table.

ANSWER INSERT INTO Book Title, Genre, Year) VALUES ('The Joy Luck Club', 'Fiction', 1989 ī‚‚;

Question 41.

The Book table has the following columns: ID—integer, primary key, auto_increment, Title—variable- length string, Genre—variable-length string, Year—integer , Write a SQL statement to delete the row with the ID value of 3 from the Book table.

ANSWER DELETE from Book WHERE ID ī‚› 3;

Question 42.

The Book table has the following columns: ID—integer, primary key, auto_increment, Title—variable- length string, Genre—variable-length string, Year—integer, Write a SQL statement to update the Year value to be 2022 for all books with a Year value of 2020.

ANSWER UPDATE Book SET Year ī‚› 2022 WHERE Year ī‚› 2020;

Which query illustrates performing an outer join of the Book table with a different table?

ANSWER SELECT Book.Title, A.Author FROM Book B RIGHT JOIN Author A ON B.AuthorID ī‚› A.ID

Question 44.

Assume there are two tables, A and B. Which rows will always be included in the result set if Table A is inner joined with Table B?

ANSWER Only rows in Tables A and B that share the join condition

Question 45.

The database contains a table named Book. Write a SQL query to return all data from the Book table without directly referencing any column names.

ANSWER SELECT * FROM Book;

Question 46.

The Book table has the following columns: ID—integer, primary key, auto_increment, Title—variable- length string, Genre—variable-length string, Year—integer, Write a SQL query to retrieve the Title and Genre values for all records in the Book table with a Year value of 2020. Ensure your result set returns the columns in the order indicated.

ANSWER SELECT Title, Genre FROM Book WHERE Year ī‚› 2020;

The Book table has the following columns: ID—integer, primary key, auto_increment, Title—variable- length string, Genre—variable-length string, Year—integer, Write a SQL query to return how many books have a Year value of 2019.

ANSWER SELECT COUNT*ī‚‚ FROM Book WHERE Year ī‚› 2019;

Question 51.

The Movie table has the following columns: ID ī‚ˆ integer, primary key, Title - variable-length string, Genre - variable-length string, RatingCode - variable-length string, Year - integer, Write a SELECT statement to select the year and the total number of movies for that year. Hint: Use the COUNT function and GROUP BY clause.

ANSWER SELECT Year, COUNT*ī‚‚ AS TotalMovies FROM Movie GROUP BY Year;

The Movie table has the following columns: ID ī‚ˆ integer, primary key, Title - variable-length string, Genre - variable-length string, RatingCode - variable-length string, Year - integer, The Rating table has the following columns: Code - variable-length string, primary key, Description - variable-length string, Write a SELECT statement to select the Title, Year, and rating Description. Display all movies, whether or not a RatingCode is available. Hint: Perform a LEFT JOIN on the Movie and Rating tables, matching the RatingCode and Code columns.

ANSWER SELECT Movie.Title, Movie.Year, Rating.Description FROM Movie LEFT JOIN Rating ON Movie.RatingCode ī‚› Rating.Code;

Question 53.

The Employee table has the following columns: ID ī‚ˆ integer, primary key, FirstName - variable-length string, LastName - variable-length string, ManagerID ī‚ˆ integer, Write a SELECT statement to show a list of all employees' first names and their managers' first names. List only employees that have a manager. Order the results by Employee first name. Use aliases to give the result columns distinctly different names, like "Employee" and "Manager". Hint: Join the Employee table to itself using INNER JOIN.

ANSWER SELECT E.FirstName AS Employee, M.FirstName AS Manager FROM Employee E JOIN Employee M ON E.ManagerID ī‚› M.ID ORDER BY E.FirstName;

Question 54.

The database has three tables for tracking horse-riding lessons:

Horse with columns: ID ī‚ˆ primary key, RegisteredName, Breed, Height, BirthDate,

HorseID ī‚ˆ partial primary key, foreign key references Horse(ID), StudentID ī‚ˆ foreign key references Student(ID), LessonDateTime - partial primary key,

Write a SELECT statement to create a lesson schedule for Feb 1, 2020 with the lesson date/time, student's first and last names, and the horse's registered name. Order the results in ascending order by lesson date/time, then by the horse's registered name. Make sure unassigned lesson times (student ID is NULLī‚‚ appear in the results. Hint: Perform a join on the LessonSchedule, Student, and Horse tables, matching the student IDs and horse IDs.

ANSWER SELECT LS.LessonDateTime, S.FirstName, S.Last-Name, H.RegisteredName FROM LessonSchedule LS LEFT JOIN Student S ON LS.StudentID ī‚› S.ID LEFT JOIN Horse H ON LS.HorseID ī‚› H.ID WHERE LS.LessonDateTime >= '2020ī‚ˆ 02 ī‚ˆ01' AND LS.LessonDateTime < '2020ī‚ˆ 02 ī‚ˆ02' ORDER BY LS.LessonDateTime ASC, H.RegisteredName ASC;

Question 56.

The Horse table has the following columns: ID ī‚ˆ integer, primary key, RegisteredName - variable-length string, Breed - variable-length string, Height - decimal number, BirthDate - date, Write a SELECT statement to select the registered name and height for only horses that have an above average height. Order the results by height (ascending). Hint: Use a subquery to find the average height.

ANSWER SELECT RegisteredName, Height From Horse Where Height > ( SELECT AVGHeight) From Horse ) Order By Height ASC;

The Movie table has the following columns: ID ī‚ˆ positive integer, Title - variable-length string, Genre - variable-length string, RatingCode - variable-length string, Year - integer, Write ALTER statements to make the following modifications to the Movie table: Add a Producer column with VARCHAR data type (max 50 chars). Remove the Genre column. Change the Year column's name to ReleaseYear, and change the data type to SMALLINT.

ANSWER ALTER Table Movie ADD Producer Varchar(50), Drop Genre, CHANGE Year ReleaseYear SMALLINT;

Question 58.

The Horse table has the following columns: ID ī‚ˆ integer, auto increment, primary key, RegisteredName - variable-length string, Breed - variable-length string, must be one of the following: Egyptian Arab, Holsteiner, Quarter Horse, Paint, Saddlebred, Height - decimal number, must be between 10.0 and 20.0, BirthDate - date, must be on or after Jan 1, 2015, Insert the following data into the Horse table: RegisteredName, Breed, Height, BirthDate, Babe, Quarter Horse, 15.3, 2015 ī‚ˆ 02 ī‚ˆ10, Independence, Holsteiner, 16.0, 2017 ī‚ˆ 03 ī‚ˆ13, Ellie, Saddlebred, 15.0, 2016 ī‚ˆ 12 ī‚ˆ22, NULL, Egyptian Arab, 14.9, 2019 ī‚ˆ 10 ī‚ˆ 12,

ANSWER INSERT INTO Horse RegisteredName, Breed, Height, BirthDate) VALUES ('Babe', 'Quarter Horse', 15.3, '2015ī‚ˆ 02 ī‚ˆ10'), ('Independence', 'Holsteiner', 16.0, '2017ī‚ˆ 03 ī‚ˆ13'), ('Ellie', 'Saddlebred', 15.0, '2016ī‚ˆ 12 ī‚ˆ22'), NULL, 'Egyptian Arab', 14.9, '2019ī‚ˆ 10 ī‚ˆ12');