Student Name Query
Consider a STUDENTS table with columns like student_code, first_name, last_name, etc. Which SQL query would display all students where the second letter in their first name is 'i'?
- A - select first_name from students where first_name like '_i%';
- B - select first_name from students where first_name like '%i_';
- C - select first_name from students where first_name like '%i%';
- D - select first_name from students where first_name like '_i_';
- E - select firstname from student where firstname like '_i%';
Explanation: The `_` character in `LIKE` matches exactly one character, and `%` matches zero or more characters.
SUBSTR Function
What does the SQL function SUBSTR('TUTORIALS POINT', -1, 1) return?
- A - T
- B - NULL
- C - 0
- D - N
- E - TUTORIALS
Explanation: SUBSTR with a negative starting position counts back from the end of the string.
SQL Join Truth
Which of the following statements is true regarding SQL joins?
- A - The join condition is not separated from other search conditions in a query.
- B - The ON clause makes code difficult to understand.
- C - The join condition for natural join is basically an equijoin of all columns with the same name.
- D - None of the above.
- E - The join condition for natural join is basically an equijoin of all columns with different name.
Explanation: Natural joins implicitly join tables based on columns sharing the same name and data type.
SQL Join Falsehood
Which of the following statements is NOT true about SQL joins?
- A - An inner join is a join of two tables returning only matching rows.
- B - A left or right outer join returns the results of the inner join as well as the unmatched rows in the left or right table respectively.
- C - A full outer join returns results of an inner join as well as the results of a left and right join.
- D - None of the above.
- E - An inner join returns all rows.
Explanation: All the statements about inner, left/right outer, and full outer joins are true.
COUNT Function
Which of the following is NOT true about the COUNT function in SQL?
- A - COUNT(*) returns the number of rows in the table.
- B - COUNT(exp) returns the number of rows with non-null values for the exp.
- C - COUNT(DISTINCT exp) returns the number of unique, non-null values in the column.
- D - All are true.
- E - COUNT(NULL) returns the number of rows in the table.
Explanation: All given statements are correct descriptions of the COUNT function's behavior.
Removing Rows From Table
Which statement about removing rows from a table using SQL is true?
- A - You remove existing rows from a table using the DELETE statement.
- B - No rows are deleted if you omit the WHERE clause.
- C - You cannot delete rows based on values from another table.
- D - All of the above.
- E - You remove rows existing rows from a table using the UPDATE statement.
Explanation: The `DELETE` statement is used to remove rows. While you can delete all rows if you omit the WHERE clause (effectively emptying the table), that is not the default/required behaviour. You *can* delete rows based on values from another table using subqueries.
CREATE TABLE
Which of the following is true about the CREATE TABLE statement in SQL?
- A - This is a DML statement.
- B - This statement also record information in the data dictionary.
- C - You don't need any privilege to use this statement.
- D - All of the above.
- E - This is a DQL Statement
Explanation: CREATE TABLE is a DDL (Data Definition Language) statement. It requires privileges and updates the data dictionary.
SQL Constraint Truth
Which of the following is NOT true about constraints in SQL?
- A - A NOT NULL constraint specifies that the column cannot have a null value.
- B - A UNIQUE constraint specifies that a column or a combination of columns must have unique values for all rows.
- C - A PRIMARY KEY is same as UNIQUE.
- D - A FOREIGN KEY enforces a foreign key relationship between a column and a referenced table.
- E - A PRIMARY KEY is similar to a UNIQUE constraint, except it cannot contain NULL values.
Explanation: A PRIMARY KEY is similar to a UNIQUE constraint, but it cannot contain NULL values and a table can only have one PRIMARY KEY.
Pseudocolumns Truth
Which of the following is NOT true about Pseudocolumns that return the sequence values?
- A - NEXTVAL returns the next available sequence value.
- B - CURRVAL gets the current sequence value.
- C - PREVVAL gets the previous sequence value.
- D - None of the above.
- E - LASTVAL returns the last sequence value
Explanation: There is no standard pseudocolumn called `PREVVAL`. `CURRVAL` retrieves the current value, and `NEXTVAL` generates the next value.
Granting Privileges
Which code snippet correctly grants the privileges of creating tables and views to a role named 'student_admin'?
- A - grant create table, create view to student_admin;
- B - grant to student_admin create table, create view;
- C - grant role student_admin create table, create view;
- D - None of the above.
- E - grant create view to student_admin create table;
Explanation: The `GRANT` statement syntax is `GRANT privilege1, privilege2 TO role_name;`
LIKE operator
Which of the following SQL statements uses the LIKE operator to find names starting with 'A'?
- A - SELECT name FROM table WHERE name LIKE 'A%';
- B - SELECT name FROM table WHERE name LIKE '%A';
- C - SELECT name FROM table WHERE name = 'A';
- D - SELECT name FROM table WHERE name LIKE '_A';
- E - SELECT name FROM table WHERE name CONTANIS 'A';
Explanation: The `LIKE` operator with 'A%' finds names starting with 'A'.
DISTINCT Keyword
What is the purpose of the DISTINCT keyword in a SELECT statement?
- A - It sorts the result set.
- B - It filters rows based on a condition.
- C - It returns only unique values.
- D - It counts the number of rows.
- E - It combines multiple tables.
Explanation: The `DISTINCT` keyword removes duplicate rows from the result set.
WHERE Clause
Which part of a SQL query specifies the condition to filter rows?
- A - SELECT
- B - FROM
- C - WHERE
- D - GROUP BY
- E - ORDER BY
Explanation: The `WHERE` clause is used to specify a condition for filtering rows.
ORDER BY Clause
How to sort a table in descending order based on a column?
- A - ORDER BY column ASC
- B - SORT BY column DESC
- C - ORDER BY column DESC
- D - SORT BY column ASC
- E - GROUP BY column DESC
Explanation: The `ORDER BY` with the `DESC` keyword sorts in descending order.
Joining Tables
Which SQL keyword is used to combine rows from two or more tables based on a related column?
- A - UNION
- B - INTERSECT
- C - JOIN
- D - EXCEPT
- E - MERGE
Explanation: The `JOIN` keyword is used to combine rows from two or more tables.