RSS Feed

Multiple Choice Questions - SQL Server 'Like'


Multiple Choice Questions - SQL Server 'Like'

Table Table_1 is created as below:
CREATE TABLE table_1 (
name varchar(50));

1.
Table Table_1 has values like:

name
forget
getting
get
jetsetget
GET

What is the result of below query:
Select * from table_1
where name like '%get'
A) Result will include all values of the table
B) Result will include 'forget' and 'jetsetget'
C) Result will include 'get' and 'GET'
D) Result will include all values of the table except 'getting'

2.
Consider the same table as above:

What is the result of below query:
select * from table_1
where name like 'get%'
A) Result will include all values of the table
B) Result will include values 'getting', 'get' and 'GET'
C) Result will include 'get' and 'GET'
D) Result will include 'forget' and 'jetsetget'

3.
Table Table_1 has values like:

name
for%get
get%ting
%get
jetsetget%
GET

What is the result of below query:
select * from table_1
where name like '%[%]get%'
A) Result will include all values of the table except 'GET'
B) Result will include 'get' and 'GET'
C) Result will include 'for%get' and '%get'
D) Result will include all values of the table

4.
Table Table_1 has values like:

name
mean
lean
dean
keean
ean

What is the result of below query:
select * from table_1
where name like '_ean'
A) Result is mean, lean, dean, keean, ean
B) Result is mean, lean, dean
C) Result is ean
D) None of above

5.
Table Table_1 has values like:

name
mean
lean
dean
keean
ean

What is the result of below query:
select * from table_1
where name like '[^_]ean'
A) Result is mean, lean, dean, keean, ean
B) Result is mean, lean, dean
C) Result is ean
D) Result is ean and Keean

6.
Table Table_1 has values like:

name
One King
Two King
Three King
Four King
Five King

Two queries are run on the above table:

a.
Select * from table_1
where name like '% King'
b.
Select * from table_1
where name like '%King'
A) Result of both the queries is same
B) Result of both the queries is different

7.
CREATE TABLE t (col1 char(30));
INSERT INTO t VALUES ('Robert King');

SELECT * 
FROM t 
WHERE col1 LIKE '% King';

A) Result of the above query is 'Robert King'
B) Above query will not return any rows.

8.
CREATE TABLE U (col1 nchar(30));
INSERT INTO U VALUES ('Robert King');
SELECT * 
FROM U 
WHERE col1 LIKE '% King';
A) Result of the above query is 'Robert King'
B) Above query will not return any rows.

9.
Table Table_1 has values like:

name
abcde
abcdf
abcdg
abcdh
abcdi

What is the result of below query:
select * from table_1
where name like 'abcd[!efghi]'
A) Result will show no rows
B) Result will show all rows
C) Result is an error
D) None of above

10.
Table Table_1 has values like:

name
10%
20%
30%
40%
50%
00%

What is the result of below query:
select * from table_1
Where name like '%0!%'
ESCAPE '!'
A) Result will show an error
B) Result will show no rows
C) Result is all the rows
D) Result is '00%'

Answers