Week 1 - 4 Flashcards

1
Q

What SQL Statement lists the table names of all the tables that you have created?

A

SELECT table_name

FROM user_tables;

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

What SQL statement lists the column details of a table that you have created?

A

DESCRIBE ;

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

What SQL Statement deletes a table?

A

DROP TABLE ;

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

Create a table called subject with typical attributes and a foreign key from a table named Lecturer.

A
Create Table SUBJECT (
SubjectCode Varchar2(10) ,
Title Varchar2(100) ,
CreditPoints Number,
LecId Number,
Primary Key (SubjectCode),
Foreign Key (LecId) References Lecturer
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A parent key is found at the a)______ end of an M:1 relationship and the child is found at the b)______ end of an M:1 relationship.

A

a) One

b) Many

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

What does the following error indicate?

ORA-02292: integrity constraint (s1234567.SYS_C002969703) violated - child record found

A

A parent (primary key) value has attempted to be deleted without first deleting the child (foreign key) value.

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

What does the following error indicate?

ORA-02291: integrity constraint (s1234567.SYS_C002969703) violated - parent key not found

A

No parent (primary key) value matched the value attempted to be used in the constraint.

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

Write an SQL statement that inserts values into a SUBJECT table but the lecturer is unknown.

A

INSERT INTO SUBJECT ( SubjectCode, Title, CreditPoints, LecId )
VALUES (‘INF21009’, ‘Advanced Facebook’, 12.5, Null);

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

How would you edit the following SQL statement if every subject MUST have a convener and every subject NEEDS a title?

Create Table SUBJECT (
SubjectCode Varchar2(10) ,
Title Varchar2(100) ,
CreditPoints Number,
LecId Number,
Primary Key (SubjectCode),
Foreign Key (LecId) References Lecturer
);
A
Create Table SUBJECT (
SubjectCode Varchar2(10) ,
Title Varchar2(100) Not Null,
CreditPoints Number,
LecId Number Not Null,
Primary Key (SubjectCode),
Foreign Key (LecId) References Lecturer
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the following error indicate?

ORA-01400: cannot insert NULL into (s1234567.SUBJECT.LECID)

A

An attempt has been made to insert a row that breaks the Not Null constraint.

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

A single line indicates that participation is a)_____.

A circle indicates that participation is b)_____.

A

a) MUST

b) MAY

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

Write an SQL statement that shows the columns Test1 and Test2 individually and then sum them together in a column named TestSum. Make this from a table called StudentResults.

A

SELECT Test1, Test2, Test1+Test2 AS “TestSum”

FROM StudentResults;

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

Write an SQL statement that shows an alternate column name to a column named Name from the table StudentResults.

A

SELECT Name “StudentName”

FROM StudentResults;

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

Write the following SQL statement using alias’s.

SELECT lecturer.LecId, subject.SubjName, lecturer.Age
FROM lecturer
INNER JOIN subject
ON lecturer.LecId = subject.LecId
WHERE lecturer.age => 50 AND subject.SubjName = ‘Database’;

A
SELECT L.LecId, S.SubjName, L.Age
FROM lecturer L
INNER JOIN subject S
ON L.LecId = S.LecId
WHERE L.Age => 50 AND S.SubjName = 'Database';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When a WHERE clause contains both an AND & OR operator then the ___ operators take precedence and must be evaluated first.

A

AND

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

SELECT * FROM Emp WHERE branch = ‘City’;

If the above SQL statement selects all people who work in the City branch, write a statement that:

a) selects all people from all other brances
b) select all people who work in either City or Haw
c) select all people from all branches except City or Haw

A

a)
SELECT * FROM Emp WHERE NOT (branch = ‘City’);

b)
SELECT * FROM Emp WHERE branch = ‘City’ OR branch=’Haw’;

c)
SELECT * FROM Emp WHERE NOT (branch=’City’ OR branch=’Haw’);

17
Q

Does the following SQL statements return different results?

SELECT * FROM emp WHERE NOT ( Dept = 1 OR Dept = 2);

SELECT * FROM emp WHERE NOT Dept = 1 OR Dept = 2

A

Yes.

18
Q

What is the order of precedence for the following?

Brackets, NOT, Relational Operators (, = etc.), OR, AND.

A
  1. Relational Operators (, = etc.)
  2. Brackets
  3. NOT
  4. AND
  5. OR
19
Q

What is the syntax to return a value where a) all characters are in upper case, and b) all characters are in lower case?

A

a)
UPPER ()

b)
LOWER ()

20
Q

Select all columns from a table Employee with multiple Smiths in the sname column. Note that some of them have all uppercase letters.

A

SELECT *
FROM Employee
Where UPPER(sname) = ‘SMITH’;

21
Q

What is an alternative way to write:

WHERE age >= 30 AND age <= 40

A

WHERE age BETWEEN 30 and 40

22
Q

Write a WHERE clause that partially matches a text value like the following:

a) starting with J
b) ending in J
c) That has a J anywhere in it
d) That has JO in it next to each other
e) That has JON in it next to each other
f) That has J and an O anywhere in it but in that order

A

a) WHERE UPPER(name) LIKE ‘J%’
b) WHERE UPPER(name) LIKE ‘%J’
c) WHERE UPPER(name) LIKE ‘%J%’
d) WHERE UPPER(name) LIKE ‘%JO%’
e) WHERE UPPER(name) LIKE ‘%JON%’
f) WHERE UPPER(name) LIKE ‘%J%O%’

23
Q

What is an alternative way to write…
a)
WHERE upper(name) = ‘JONES’ OR upper(name) = ‘BROWN’ OR upper(name) = ‘LEE’ OR upper(name) = ‘JOHNSON’

b)
WHERE age = 24 OR age = 26 OR age = 28 OR age = 30

A
a)
WHERE upper(name) IN ('JONES', 'BROWN', 'LEE', 'JOHNSON')

b)
WHERE age IN (24, 26, 28, 30)

24
Q

Write a WHERE clause that searches for heights that have null values and names that don’t have null values

A

WHERE height IS NULL OR name IS NOT NULL

25
Q

Write an SQL statement that will not select multiple rows with the same value in the column Country from a table called Student

A

SELECT DISTINCT Country FROM Student;
or
SELECT UNIQUE Country FROM Student;