Machine-translated by Google. Questions are authored in English.
Top

Introduction to SQL Questions and Answers

1.

Which of the following languages is referred to as a database language?

Exam Year(s)

DSSSB TGT - 2023,

Answer: A

SQL (Structured Query Language) is the database language, used to define, query and manage data in relational databases. HTML is a markup language for web pages, Python is a general-purpose programming language, and VJ++ (Visual J++) is a language for Java development on Microsoft platforms. None of those three is a database language. The language has commands such as SELECT, INSERT, UPDATE and DELETE for working with the data in tables.

Please log in or register to report this question.

2.

Consider the following two tables and four queries in SQL.

Book (isbn, bname), Stock (isbn, copies)

Query 1: SELECT B.isbn, S.copies
FROM Book B INNER JOIN Stock S
ON B.isbn = S.isbn;

Query 2: SELECT B.isbn, S.copies
FROM Book B LEFT OUTER JOIN Stock S
ON B.isbn = S.isbn;

Query 3: SELECT B.isbn, S.copies
FROM Book B RIGHT OUTER JOIN Stock S
ON B.isbn = S.isbn;

Query 4: SELECT B.isbn, S.copies
FROM Book B FULL OUTER JOIN Stock S
ON B.isbn = S.isbn;

Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries?

Exam Year(s)

GATE CS - 2018,

Answer: D

The query certain to give a superset is Query 4, the full outer join.

The inner join returns only books with a matching stock row. The left outer join adds books with no stock row (with copies null), and the right outer join adds stock rows with no matching book (with B.isbn null). The full outer join returns the matched rows plus both kinds of unmatched rows, so every row of the other three appears in it.

The left join misses the unmatched stock rows, and the right join misses the unmatched books, so neither is certain to contain the other. The inner join is contained in all the others, which makes it the smallest result, not the largest.

Please log in or register to report this question.

3.

Which of the following is valid SQL for an Index?

Answer: A

Correct answer: CREATE INDEX ID;

CREATE INDEX is the statement that builds an index, following the same CREATE pattern as tables and views - in full, CREATE INDEX name ON table (column).

An index is a separate structure that lets the engine find rows by a column's value without scanning the whole table, at the cost of space and of slower writes, since every insert and update must maintain it. The counterpart is DROP INDEX. CHANGE, ADD and REMOVE are not SQL statements in their own right.

Please log in or register to report this question.

Answer: C

Correct answer: has a distinct form that cannot be duplicated by a join.

Many subqueries can be rewritten as joins, but not all. A correlated EXISTS or NOT EXISTS, and a comparison against an aggregate of a related set - WHERE salary > (SELECT AVG(salary) FROM emp) - have no direct join equivalent.

The reason is that a join combines rows while a subquery can compute a value or test existence without producing rows. Subqueries are also not limited to two tables, and their outer query can certainly be sorted with ORDER BY.

Please log in or register to report this question.

5.

A subquery in an SQL SELECT statement is enclosed in:

Answer: C

Correct answer: parenthesis -- (...) .

A subquery is written inside ordinary parentheses, as in WHERE id IN (SELECT id FROM other).

Braces and square brackets have other roles: square brackets delimit identifiers in some dialects, such as SQL Server's [Order Details], and braces appear in ODBC escape sequences - neither encloses a subquery in standard SQL. The parentheses are not decoration; they mark where the inner query ends, which is what lets subqueries nest inside one another.

Please log in or register to report this question.

6.

________ was adopted as a national standard by ANSI in 1992.

Answer: B

Correct answer: SQL

SQL was adopted as an ANSI standard in 1986 and substantially revised as SQL-92, which ANSI adopted in 1992 and which remains the reference point for the language's core.

SQL-92 fixed much of what is now taken for granted: the JOIN syntax in the FROM clause, the % and _ wildcards, and standard data types. The other options are products rather than standards - Oracle, Access and dBase are implementations, and it is precisely the standard that lets skills move between them.

Please log in or register to report this question.

7.

The benefits of a standard relational language include which of the following?

Answer: A

Correct answer: Reduced training costs

A standard language means the skill transfers. Someone who knows SQL can work with Oracle, PostgreSQL, MySQL or SQL Server without learning a new query language for each, so training costs fall and staff are easier to recruit.

The second option states the opposite of a benefit: a standard reduces dependence on a single vendor, since applications can be moved. And applications are certainly still needed - SQL queries the data; it does not supply the interface or the business logic around it.

Please log in or register to report this question.

8.

In SQL, the WHERE clause filters rows before grouping while HAVING filters after grouping.

Answer: B

Correct answer: True

WHERE is applied to individual rows before GROUP BY forms the groups, so it cannot refer to an aggregate. HAVING is applied to the groups afterwards, which is why a condition such as COUNT(*) greater than 5 must go there.

Please log in or register to report this question.

9.

There is an equivalent join expression that can be substituted for all subquery expressions.

Answer: B

Correct answer: False

Some subqueries have no join equivalent. A correlated NOT EXISTS, or a comparison against an aggregate of a related set such as WHERE salary > (SELECT AVG(salary) FROM emp), cannot be expressed as a join.

The reason is structural: a join produces rows by combining them, whereas a subquery can return a single computed value or merely test whether any row exists. Many subqueries can be rewritten as joins, and doing so sometimes helps the optimiser - but the statement claims all of them can, and that is what makes it false.

Please log in or register to report this question.

Answer: B

Correct answer: limits the row data are returned.

WHERE is a filter on rows: it tests each candidate row against a condition and keeps those for which the condition is true.

Which columns come back is decided in the SELECT list instead. The distinction is worth holding onto because the two operations are separate in relational terms - selection chooses rows, projection chooses columns - and SQL expresses them in different clauses. Since WHERE does only the first, the option claiming both is wrong.

Please log in or register to report this question.

Loading…
Tags: Introduction to SQL Questions and Answers || Introduction to SQL MCQ Questions and Answers || Introduction to SQL GK Questions and Answers || Introduction to SQL GK MCQ Questions || Introduction to SQL Multiple Choice Questions and Answers || Introduction to SQL GK || GK on Introduction to SQL || Database Questions and Answers || Database MCQ Questions and Answers || Database GK Questions and Answers || GK on Database