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

Introduction to SQL Questions and Answers

91.

An attribute A of datatype varchar(20) has the value “Avi” . The attribute B of datatype char(20) has value ”Reed” .Here attribute A has ____ spaces and attribute B has ____ spaces .

Answer: A

Correct answer: 3, 20

The attributes are asked for as stored, not as supplied. A is varchar(20) holding "Avi", and a varying-length type stores only the characters given, so it occupies 3.

B is char(20) holding "Reed". A fixed-length type pads to its full width with trailing spaces, so it occupies 20 whatever the value's length. That padding has a consequence beyond storage: comparisons and concatenations may carry the trailing spaces, which is why char is reserved for values that really are of fixed width.

Please log in or register to report this question.

92.

Scalar aggregate are multiple values returned from an SQL query that includes an aggregate function.

Answer: B

Correct answer: False

A scalar aggregate is a single value, produced when an aggregate function is applied to a whole table with no GROUP BY - SELECT COUNT(*) FROM orders returns one row of one column.

The multiple-value case is the vector aggregate, produced when GROUP BY divides the rows into groups and the function is computed once per group. The statement swaps the two definitions, which is what makes it false; "scalar" means single-valued in this context as it does elsewhere.

Please log in or register to report this question.

93.

SQL query and modification commands make up a(n) ________ .

Answer: B

Correct answer: DML

DML is the Data Manipulation Language - the subset of SQL that works with the data itself: SELECT to query it and INSERT, UPDATE and DELETE to change it.

DDL, by contrast, defines the structures the data lives in, through CREATE, ALTER and DROP. The practical difference is not only conceptual: in most engines DDL statements commit implicitly, while DML statements participate in a transaction and can be rolled back.

Please log in or register to report this question.

94.

The SQL statement: SELECT Name, COUNT(*) FROM NAME_TABLE; counts the number of name rows and displays this total in a table with a single row and a single column.

Answer: B

Correct answer: False

The statement mixes an ungrouped column with an aggregate. Name has one value per row while COUNT(*) has one value for the whole table, and there is no rule for pairing them.

Standard SQL rejects the query, and so do most engines in their default configuration. Either drop the column, giving SELECT COUNT(*) FROM NAME_TABLE and a single row, or add GROUP BY Name, giving one row per distinct name with its own count - but not the single row the statement describes.

Please log in or register to report this question.

95.

Indexes may be created or dropped at any time.

Answer: A

Correct answer: True

Indexes are physical structures, separate from the logical design, so CREATE INDEX and DROP INDEX can be issued at any time without altering the tables or the queries that use them.

That independence is the point: an index changes how fast a query runs, never what it returns, so one can be added when a query proves slow and dropped when it is no longer earning its keep. The practical caveat is timing rather than legality - building an index on a large table takes time and may lock it, so it is usually done off-peak.

Please log in or register to report this question.

Answer: C

Correct answer: a data sublanguage.

SQL is called a data sublanguage because it does one part of the job and relies on a host language for the rest. It expresses what data is wanted, but has no general control flow, no user interface and no way to build an application on its own.

So it is embedded in C, Java or Python, which supply the loops, the branching and the presentation. It is not an operating system, and it is not a DBMS - Oracle and PostgreSQL are DBMSs, and SQL is the language through which they are addressed.

Please log in or register to report this question.

97.

The keyword LIKE can be used in a WHERE clause to refer to a range of values.

Answer: B

Correct answer: False

LIKE matches text patterns using % and _; it has no notion of a range and cannot express "between these two values".

Ranges are BETWEEN's work, or the comparison operators >= and <=. The two constructs also behave differently against an index: an equality or range test can use one, while a LIKE pattern beginning with a wildcard cannot, since there is no prefix to seek on.

Please log in or register to report this question.

98.

The SQL statement: SELECT Number1 + Number 2 AS Total FROM NUMBER_TABLE; adds two numbers from each row together and lists the results in a column named Total.

Answer: A

Correct answer: True

The SELECT list may contain expressions as well as plain columns, so Number1 + Number2 is evaluated once per row and its value returned.

AS Total gives the resulting column a name; without it the heading would be the expression itself, which is awkward for a program or a report to reference. One caution: if either operand is null the whole expression is null, since arithmetic with an unknown value gives an unknown result. COALESCE is the usual remedy where zero is the sensible substitute.

Please log in or register to report this question.

Answer: B

Correct answer: percent sign (%); underscore (_)

In standard SQL, % matches any sequence of characters including none, and _ matches exactly one character.

So LIKE 'S%' finds anything beginning with S, while LIKE 'S_ith' finds Smith and Swith but not Sith. Both are used with LIKE. Microsoft Access departs from the standard, using * and ? for the same two roles - a difference that quietly breaks queries moved between the two.

Please log in or register to report this question.

100.

SQL is a programming language.

Answer: B

Correct answer: False

SQL is a data sublanguage, not a general-purpose programming language. It has no loops, no branching and no way to build an interface, so it cannot express a complete program on its own and is embedded in a host language that supplies those.

It is also declarative: a query states what data is wanted and leaves the optimiser to decide how to get it, where a programming language specifies the steps. Procedural extensions such as PL/SQL and T-SQL add control flow, but those are dialect additions built on top of SQL rather than SQL itself.

Please log in or register to report this question.

Loading…

Other Subjects

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