Week 1 - 4 Flashcards
What SQL Statement lists the table names of all the tables that you have created?
SELECT table_name
FROM user_tables;
What SQL statement lists the column details of a table that you have created?
DESCRIBE ;
What SQL Statement deletes a table?
DROP TABLE ;
Create a table called subject with typical attributes and a foreign key from a table named Lecturer.
Create Table SUBJECT ( SubjectCode Varchar2(10) , Title Varchar2(100) , CreditPoints Number, LecId Number, Primary Key (SubjectCode), Foreign Key (LecId) References Lecturer );
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) One
b) Many
What does the following error indicate?
ORA-02292: integrity constraint (s1234567.SYS_C002969703) violated - child record found
A parent (primary key) value has attempted to be deleted without first deleting the child (foreign key) value.
What does the following error indicate?
ORA-02291: integrity constraint (s1234567.SYS_C002969703) violated - parent key not found
No parent (primary key) value matched the value attempted to be used in the constraint.
Write an SQL statement that inserts values into a SUBJECT table but the lecturer is unknown.
INSERT INTO SUBJECT ( SubjectCode, Title, CreditPoints, LecId )
VALUES (‘INF21009’, ‘Advanced Facebook’, 12.5, Null);
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 );
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 );
What does the following error indicate?
ORA-01400: cannot insert NULL into (s1234567.SUBJECT.LECID)
An attempt has been made to insert a row that breaks the Not Null constraint.
A single line indicates that participation is a)_____.
A circle indicates that participation is b)_____.
a) MUST
b) MAY
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.
SELECT Test1, Test2, Test1+Test2 AS “TestSum”
FROM StudentResults;
Write an SQL statement that shows an alternate column name to a column named Name from the table StudentResults.
SELECT Name “StudentName”
FROM StudentResults;
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’;
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';
When a WHERE clause contains both an AND & OR operator then the ___ operators take precedence and must be evaluated first.
AND