This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Wildcards”.
1. A wildcard operator is used to _________ any other character(s) in a string.
a) Substitute
b) Eliminate
c) Modify
d) Shift
View Answer
Explanation: Wildcard operators are used as an alternate for one or more than one characters while searching. A wildcard operator is used to substitute other characters in a string.
2. Wildcard characters are used with which of the following operators?
a) Between
b) Range
c) In
d) Like
View Answer
Explanation: Wildcard characters are used with the SQL LIKE operator. This LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
3. How many wildcards can be used with LIKE operator in SQL?
a) One
b) Two
c) Three
d) Four
View Answer
Explanation: Two wildcards can be used with the LIKE operator. They are % and _. % represents zero or more characters. _ represents a single character.
4. Which of the following wildcards can be used in MS Access and SQL server?
a) [char list], [ _ ]
b) [char list], [!char list]
c) [%], [ _ ]
d) [^char list], [ _ ]
View Answer
Explanation: MS Access uses a question mark (?) instead of underscore (_). MS Access and SQL server can use [char list] and [!char list] wildcards.
5. [char list] wildcard represents _______
a) Set of characters only
b) Range of characters only
c) Sets and ranges of characters to match
d) Domain of characters to match
View Answer
Explanation: [char list] defines sets and ranges of characters to match. It is used to fetch matching set or range of characters specified inside the brackets.
6. [^ char list] is used to fetch ___________ set or range of characters specified in the char list.
a) Matching
b) Non Matching
c) Deleted
d) Updated
View Answer
Explanation: [^ char list] and [! char list] represents same wildcard. It is used to fetch non-matching set or range of characters specified in the char list inside the brackets.
7. Which of the following is a correct syntax that uses [char list] wildcard?
a)
SELECT * FROM TABLE_NAME WHERE column_name LIKE ‘[xyz]%’;
b)
SELECT * FROM TABLE_NAME WHERE column_name LIKE ‘[xyz]’’%’;
c)
SELECT * FROM TABLE_NAME WHERE column_name LIKE _‘[x-z]’;
d)
SELECT * FROM TABLE_NAME WHERE column_name LIKE ‘[xyz]’%;
Explanation: [char list] is a wildcard, in which char list Specifies ranges of characters and sets to match. To match a pattern using LIKE operator, the whole pattern must be enclosed in single quotations.
8. Which of the following pattern is used to search for a string which doesn’t starts with letters from m to r and ends with at least 2 characters?
a) [m-r]%%
b) [!m-r]_ _ %
c) [^mr]_ %
d) [m-r]_ % _
View Answer
Explanation: Using this [!char list], we can specify more than one character in ‘char list’ to search and not to match them in a given string. _ Character matches with exactly one character. % character matches one or more characters.
9. Wildcards cannot be used as a substitute for special characters i.e. characters other than alphabets.
a) True
b) False
View Answer
Explanation: Wildcards can be used in the place of special characters. To search for a string with value ‘a@bc’, we can use ‘a%bc’ or ‘a_bc’ patterns in LIKE clause.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.