|
Know
More About MS SQL
What is difference between DELETE &
TRUNCATE commands?
Delete command removes the rows from a
table based on the condition that we
provide with a WHERE clause. Truncate
will actually remove all the rows from a
table and there will be no data in the
table after we run the truncate command.
TRUNCATE
TRUNCATE is faster and uses fewer system
and transaction log resources than
DELETE.
TRUNCATE removes the data by
deallocating the data pages used to
store the table’s data, and only the
page deallocations are recorded in the
transaction log.
TRUNCATE removes all rows from a table,
but the table structure and its columns,
constraints, indexes and so on remain.
The counter used by an identity for new
rows is reset to the seed for the
column.
You cannot use TRUNCATE TABLE on a table
referenced by a FOREIGN KEY constraint.
Because TRUNCATE TABLE is not logged, it
cannot activate a trigger.
TRUNCATE can not be Rolled back using
logs.
TRUNCATE is DDL Command.
TRUNCATE Resets identity of the table.
DELETE
DELETE removes rows one at a time and
records an entry in the transaction log
for each deleted row.
If you want to retain the identity
counter, use DELETE instead. If you want
to remove table definition and its data,
use the DROP TABLE statement.
DELETE Can be used with or without a
WHERE clause
DELETE Activates Triggers.
DELETE Can be Rolled back using logs.
DELETE is DML Command.
DELETE does not reset identity of the
table.
Difference between Function and
Stored Procedure?
UDF can be used in the SQL statements
anywhere in the WHERE/HAVING/SELECT
section where as Stored procedures
cannot be.
UDFs that return tables can be treated
as another rowset. This can be used in
JOINs with other tables.
Inline UDF’s can be though of as views
that take parameters and can be used in
JOINs and other Rowset operations.
When is the use of UPDATE_STATISTICS
command?
This command is basically used when a
large processing of data has occurred.
If a large amount of deletions any
modification or Bulk Copy into the
tables has occurred, it has to update
the indexes to take these changes into
account. UPDATE_STATISTICS updates the
indexes on these tables accordingly.
What types of Joins are possible with
Sql Server?
Joins are used in queries to explain how
different tables are related. Joins also
let you select data from a table
depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs,
CROSS JOINs. OUTER JOINs are further
classified as LEFT OUTER JOINS, RIGHT
OUTER JOINS and FULL OUTER JOINS.
What is the difference between a
HAVING CLAUSE and a WHERE CLAUSE?
Specifies a search condition for a group
or an aggregate. HAVING can be used only
with the SELECT statement. HAVING is
typically used in a GROUP BY clause.
When GROUP BY is not used, HAVING
behaves like a WHERE clause. Having
Clause is basically used only with the
GROUP BY function in a query. WHERE
Clause is applied to each row before
they are part of the GROUP BY function
in a query. HAVING criteria is applied
after the the grouping of rows has
occurred.
What is sub-query? Explain properties
of sub-query.
Sub-queries are often referred to as
sub-selects, as they allow a SELECT
statement to be executed arbitrarily
within the body of another SQL
statement. A sub-query is executed by
enclosing it in a set of parentheses.
Sub-queries are generally used to return
a single row as an atomic value, though
they may be used to compare values
against multiple rows with the IN
keyword.
A sub query is a SELECT statement that
is nested within another T-SQL
statement. A sub query SELECT statement
if executed independently of the T-SQL
statement, in which it is nested, will
return a result set. Meaning a sub query
SELECT statement can standalone and is
not depended on the statement in which
it is nested. A sub query SELECT
statement can return any number of
values, and can be found in, the column
list of a SELECT statement, a FROM,
GROUP BY, HAVING, and/or ORDER BY
clauses of a T-SQL statement. A Sub
query can also be used as a parameter to
a function call. Basically a sub query
can be used anywhere an expression can
be used.
Properties of Sub-Query
A sub query must be enclosed in the
parenthesis.
A sub query must be put in the right
hand of the comparison operator, and
A sub query cannot contain a ORDER-BY
clause.
A query can contain more than one
sub-queries.
What are types of sub-queries?
Single-row sub query, where the sub
query returns only one row.
Multiple-row sub query, where the sub
query returns multiple rows,. and
Multiple column sub query, where the sub
query returns multiple columns.
|