Set-02

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

SQL Questions Set-02

1. How many types of SQL Language? OR What are the subsets of


SQL?
Ans: The following are the five types of SQL Languages:

● Data definition language (DDL): It defines the data structure that


consists of commands like CREATE, ALTER, DROP, etc.

● Data manipulation language (DML): It is used to manipulate


existing data in the database. The commands in this category are
SELECT, UPDATE, INSERT, etc.

● Data control language (DCL): It controls access to the data stored


in the database. The commands in this category include GRANT and
REVOKE.

● Transaction Control Language (TCL): It is used to deal with the


transaction operations in the database. The commands in this category
are COMMIT, ROLLBACK, SET TRANSACTION, SAVEPOINT, etc.

● Data Query Language (DQL): The commands of SQL that are used
to retrieve data from the database are collectively called DQL. So all
Select statements come under DQL
2. What is the purpose of DDL Language?

Ans: DDL stands for Data definition language. It is the subset of a database
that defines the data structure of the database when the database is created. For
example, we can use the DDL commands to add, remove, or modify tables. It
consists of the following commands: CREATE, ALTER and DELETE database
objects such as schema, tables, indexes, view, sequence, etc.
/

SQL Questions Set-02

3. What is the purpose of DML Language?

Ans: The commands of SQL that are used to insert data into the database,
modify the data of the database, and delete data from the database are
collectively called DML. Examples include Insert, Update and Delete. This
impacts the Data structure.

4. What is Data Query Language (DQL)?


Ans: The commands of SQL that are used to retrieve data from the
database are collectively called DQL. So all Select statements come
under DQL.

5. What is Data Control Language (DCL)?


Ans: The commands of SQL that are used to control the access to data
stored in the database are collectively called DCL and examples
include Grant and Revoke.

6. What is Transaction Control Language (TCL)?


Ans: The commands of SQL that are used to control the transactions
made against the database are collectively called TCL and examples
include Commit & Rollback.

7. What is the difference between TRUNCATE, DELETE and DROP?


Ans:
TRUNCATE
► TRUNCATE is a DDL command
► TRUNCATE is executed using a table lock and the whole table is locked to
remove all records.
► We cannot use the Where clause with TRUNCATE.
► TRUNCATE removes all rows from a table.
► Minimal logging in the transaction log, so it is performance-wise faster.
► TRUNCATE TABLE removes the data by deallocating the data pages used
to store the table data and
records only the page deallocations in the transaction log.
► Identify column is reset to its seed value if the table contains an identity
column.
SQL Questions Set-02

► To use Truncate on a table you need at least ALTER permission on the


table.
► Truncate uses less transaction space than Delete statement.
► Truncate cannot be used with indexed views.

DELETE:
► DELETE is a DML command.
► DELETE is executed using a row lock, each row in the table is locked for
deletion.
► We can use the where clause with DELETE to filter & delete specific
records.
► The DELETE command is used to remove rows from a table based on the
WHERE conditions.
► It maintains the log, so it is slower than truncates.
► The DELETE statement removes rows one at a time and records an entry
in the transaction log
for each deleted row.
► Identity of column keep DELETE retains the identity.
► To use Delete you need DELETE permission on the table.
► Delete uses more transaction space than a Truncate statement.
► The delete can be used with indexed views.

DROP:
► The DROP command removes a table from the database.
► All the tables' rows, indexes, and privileges will also be removed.
► No DML triggers will be fired.
► The operation cannot be rolled back.
► DROP and TRUNCATE are DDL commands, whereas DELETE is a DML
command.
► DELETE operations can be rolled back (undone), while DROP and
TRUNCATE operations cannot be rolled back.
SQL Questions Set-02

7. Which is faster Truncate or Delete? Give the reason.


Ans: Truncate is faster than delete because Truncate maintains minimal
logging in the transaction log.

8. What is the difference between CHAR and VARCHAR?

Ans: CHAR is a fixed-length string data type, so any remaining space in the
field is padded with blanks. CHAR takes up 1 byte per character. So, a
CHAR(100) field (or variable) takes up 100 bytes on a disk, regardless of the
string it holds.

VARCHAR is a variable-length string data type, so it holds only the


characters you assign to it. VARCHAR takes up 1 byte per character, + 2
bytes to hold length information. For example, if you set a VARCHAR(100)
data type = ‘Jen’, then it would take up 3 bytes (for J, E, and N) plus 2
bytes, or 5 bytes in all.

9. What is the difference between VARCHAR and NVARCHAR?


Ans:
VARCHAR :

● It is a variable-length data type


● Used to store non-Unicode characters
● Occupies 1 byte of space for each character

NVARCHAR:

● It is a variable-length data type


● Used to store Unicode characters
● Occupies 2 bytes of space for each character
SQL Questions Set-02

10. What does N mean in SQL?


Ans: You might wonder what the N stands for? N stands for National
Language Character Set and is used to specify a Unicode string. When
using Unicode data types, a column can store any character defined by
the Unicode Standard, which includes all of the characters defined in
the various character sets. Note that Unicode data types take twice as
much storage space as non-Unicode data types.

To Get the Pdf Please follow


and Comment Yes

You might also like