Chapter 02 Introducing SQL Flashcards
(30 cards)
What is DML and what is it used for?
Database Manipulation Language is used to access, insert, modify, or delete data in the existing structures of the database.
DML Statements: SELECT, INSERT, UPDATE, DELETE, MERGE, EXPLAIN PLAN, LOCK TABLE,
What is DDL and what is it used for?
Data Definition Language is used to define, alter, or drop database objects and their privileges.
DDL Statements: CREATE, ALTER, DROP, RENAME, TRUNCATE, GRANT, REVOKE, AUDIT, NOAUDIT, COMMENT
How do you write the concatenation operator?
||
‘Oracle12c’ || ‘Database’ results in ‘Oracle12cDatabase’.
What is a query?
A query is a request for information from the database tables.
Does query modify data? If not, what does it do?
Queries do not modify data; they read data from database tables and views.
A table is used to [Blank] and is [Blank] in rows and columns.
A table is used to store data and is stored in rows and columns.
What does the SELECT statement do?
It allows you to retrieve information already stored in the database.
Column Alias Name Keyword
AS
Keyword to ensure unique rows
DISTINCT
What is the DUAL table and what is it used for?
The DUAL table is a special table available to all users in the database. The DUAL table is mostly used to select system variables or to evaluate an expression.
What is the LIKE keyword?
Using the LIKE operator, you can perform pattern matching.
The pattern-search character % is used to match any character and any number of characters.
The pattern-search character _ is used to match any single character.
What is the ORDER BY keyword?
ORDER BY clause to sort the resulting rows in a specific
order based on the data in the columns.
ASC
DESC
You issue the following query: SELECT salary "Employee Salary" FROM employees; How will the column heading appear in the result? A. EMPLOYEE SALARY B. EMPLOYEE_SALARY C. Employee Salary D. employee_salary
C. Column alias names enclosed in quotation marks will appear as typed. Spaces and mixed case appear in the column alias name only when the alias is enclosed in double quotation marks.
SELECT empno enumber, ename FROM emp ORDER BY 1;
2. SELECT empno, ename FROM emp ORDER BY empno ASC;
Which of the following is true?
A. Statements 1 and 2 will produce the same result in data.
B. Statement 1 will execute; statement 2 will return an error.
C. Statement 2 will execute; statement 1 will return an error.
D. Statements 1 and 2 will execute but produce different results.
A. Statements 1 and 2 will produce the same result. You can use the column name,
column alias, or column position in the ORDER BY clause. The default sort order is
ascending. For a descending sort, you must explicitly specify that order with the DESC
keyword.
You issue the following SELECT statement on the EMP table shown in question 2.
SELECT (200+((salary*0.1)/2)) FROM emp;
What will happen to the result if all the parentheses are removed?
A. No difference, because the answer will always be NULL.
B. No difference, because the result will be the same.
C. The result will be higher.
D. The result will be lower.
B. In the arithmetic evaluation, multiplication and division have precedence over addition
and subtraction. Even if you do not include the parentheses, salary*0.1 will be
evaluated first. The result is then divided by 2, and its result is added to 200.
In the following SELECT statement, which component is a literal? (Choose all that apply.) SELECT 'Employee Name: ' || ename FROM emp WHERE deptno = 10; A. 10 B. ename C. Employee Name: D. ||
A, C. Character literals in the SQL statement are enclosed in single quotation marks.
Literals are concatenated using ||. Employee Name: is a character literal, and 10 is a
numeric literal.
What will happen if you query the EMP table shown in question 2 with the following?
SELECT empno, DISTINCT ename, salary
FROM emp;
A. EMPNO, unique values of ENAME, and then SALARY are displayed.
B. EMPNO and unique values of the two columns, ENAME and SALARY, are displayed.
C. DISTINCT is not a valid keyword in SQL.
D. No values will be displayed because the statement will return an error.
D. DISTINCT is used to display a unique result row, and it should follow immediately after
the keyword SELECT. Uniqueness is identified across the row, not by a single column.
Which clause in a query restricts the rows selected? A. ORDER BY B. WHERE C. SELECT D. FROM
B. The WHERE clause is used to filter the rows returned from a query. The WHERE clause
condition is evaluated, and rows are returned only if the result is TRUE. The ORDER BY
clause is used to display the result in a certain order. The OFFSET and FETCH clauses are
used to limit the rows returned.
The following listing shows the records of the EMP table: EMPNO ENAME SALARY COMM DEPTNO --------- ---------- --------- --------- --------- 7369 SMITH 800 20 7499 ALLEN 1600 300 30 7521 WARD 1250 500 30 7566 JONES 2975 20 7654 MARTIN 1250 1400 30 7698 BLAKE 2850 30 7782 CLARK 2450 24500 10 7788 SCOTT 3000 20 7839 KING 5000 50000 10 7844 TURNER 1500 0 30 7876 ADAMS 1100 20 7900 JAMES 950 30 7902 FORD 3000 20 7934 MILLER 1300 13000 10 When you issue the following query, which value will be displayed in the first row? SELECT empno FROM emp WHERE deptno = 10 ORDER BY ename DESC; A. MILLER B. 7934 C. 7876 D. No rows will be returned because ename cannot be used in the ORDER BY clause.
B. There are three records belonging to DEPTNO 10: EMPNO 7934 (MILLER), 7839 (KING),
and 7782 (CLARK). When you sort their names by descending order, MILLER is the first
row to display. You can use alias names and columns that are not in the SELECT clause
in the ORDER BY clause.
Refer to the listing of records in the EMP table in question 9. How many rows will the
following query return?
SELECT * FROM emp WHERE ename BETWEEN ‘A’ AND ‘C’
A. 4
B. 2
C. A character column cannot be used in the BETWEEN operator.
D. 3
D. Here, a character column is compared against a string using the BETWEEN operator, which is equivalent to ename >= ‘A’ AND ename <= ‘C’. The name CLARK will not be included in this query, because ‘CLARK’ is > ‘C’.
Refer to the EMP table in question 2. When you issue the following query, which line
has an error?
1. SELECT empno “Enumber”, ename “EmpName”
2. FROM emp
3. WHERE deptno = 10
4. AND “Enumber” = 7782
5. ORDER BY “Enumber”;
A. 1
B. 5
C. 4
D. No error; the statement will finish successfully.
C. Column alias names cannot be used in the WHERE clause. They can be used in the ORDER BY clause.
You issue the following query: SELECT empno, ename FROM emp WHERE empno = 7782 OR empno = 7876; Which other operator can replace the OR condition in the WHERE clause? A. IN B. BETWEEN ... AND ... C. LIKE D. <= E. >=
A. The IN operator can be used. You can write the WHERE clause as WHERE empno IN
(7782, 7876);. Using the =ANY operator also produces the same result.
Which statement searches for PRODUCT_ID values that begin with DI_ from the ORDERS table? A. SELECT * FROM ORDERS WHERE PRODUCT_ID = 'DI%'; B. SELECT * FROM ORDERS WHERE PRODUCT_ID LIKE 'DI_' ESCAPE '\'; C. SELECT * FROM ORDERS WHERE PRODUCT_ID LIKE 'DI\_%' ESCAPE '\'; D. SELECT * FROM ORDERS WHERE PRODUCT_ID LIKE 'DI\_' ESCAPE '\'; E. SELECT * FROM ORDERS WHERE PRODUCT_ID LIKE 'DI_%' ESCAPE '\';
C. Because _ is a special pattern-matching character, you need to include the ESCAPE
clause in LIKE. The % character matches any number of characters including 0, and _
matches a single character.
COUNTRY_NAME and REGION_ID are valid column names in the COUNTRIES table. Which
one of the following statements will execute without an error?
A. SELECT country_name, region_id,CASE region_id = 1 THEN ‘Europe’,
region_id = 2 THEN ‘America’, region_id = 3 THEN ‘Asia’, ELSE ‘Other’
END ContinentFROM countries;
B. SELECT country_name, region_id,CASE (region_id WHEN 1 THEN ‘Europe’,
WHEN 2 THEN ‘America’, WHEN 3 THEN ‘Asia’, ELSE ‘Other’) ContinentFROM
countries;
C. SELECT country_name, region_id,CASE region_id WHEN 1 THEN ‘Europe’
WHEN 2 THEN ‘America’ WHEN 3 THEN ‘Asia’ ELSE ‘Other’ END ContinentFROM
countries;
D. SELECT country_name, region_id,CASE region_id WHEN 1 THEN ‘Europe’
WHEN 2 THEN ‘America’ WHEN 3 THEN ‘Asia’ ELSE ‘Other’ ContinentFROM
countries;
C. A CASE expression begins with the keyword CASE and ends with the keyword END.