Powerful Google developer tools for immediate impact! (2023-24 C)
Sql server difference faqs- 8
1. 1.Difference between Constraints and Triggers
S.No Constraints Triggers
1 Once we define some constraint in It will be stored as separate object
a table they will be stored along
with table definition
2 Constraints will do memory Triggers will do table to table
location to table comparison. comparison.For this triggers will use
magic tables(inserted,deleted).
3 In the order of precedence first In the order of precedence only after
Constraints will be fired Constraints is fired,then only Triggers
will be fired
4 Performance wise Constraints will Performance wise triggers will give
not give best performance because best performance because table to table
memeory location to table comparison is faster than memeory
comparison is slower than table to location to table comparison.
table comparison.
5 Constraints cannot start a chain Triggers are used to carry out tasks
reaction as like triggers - for which cant be done using constraints.
instance each delete, update action For eg:-A change in the "sal" column
etc. can trigger off another of a table should change the "tax"
function column in another table.This cant be
done using constraints.It has to be
done using triggers.Thats where the
importance of triggers lie.
6 Constraint is used for column Trigger is used for table
7 Constraints are predefined Trigger is a user defined business rule
business rules in which all the for which user is responasible for logic
organisations follow this for business rule
constraints without any
modification.
8 Constraints are used to maintain Triggers are bascically stored
the integrity and atomicity of procedures which automaticallly fired
database .In other words it can be when any insert,update or delete is
said they are used to prevent issued on table
invalid data entry . the main 5
constraints are
NOT NULL,PRIMARY
KEY,FOREIGN KEY,UNIQUE
KEY and CHECK
2. 2.Difference between Cast and Convert in SQL Server
S.No Cast Convert
1 Cast is ANSII Standard Convert is Specific to SQL SERVER
2 Cast cannot be used for Convert can be used for Formatting
Formatting Purposes. Purposes.For example Select convert
(varchar, datetime, 101)
3 Cast cannot convert a datetime to Convert can be used to convert a
specific format datetime to specific format
4 Usage of CAST: Usage of CONVERT:
USE Sample USE Sample
GO GO
SELECT SUBSTRING(Name, 1, SELECT SUBSTRING(Name, 1, 30)
30) AS ProductName, ListPrice AS ProductName, ListPrice
FROM Production.Product FROM Production.Product
WHERE CAST(ListPrice AS int) WHERE CAST(int, ListPrice) LIKE
LIKE '3%'; '3%';
GO GO
3.Difference between CUBE and ROLLUP
S.No CUBE ROLLUP
1 It is an additional switch to It is an extension to GROUP BY
GROUP BY clause. It can be clause. It’s used to extract statistical
applied to all aggregation and summarized information from
functions to return cross tabular result sets. It creates groupings and
result sets. then applies aggregation functions on
them.
2 Produces all possible Produces only some possible subtotal
combinations of subtotals combinations
specified in GROUP BY clause
and a Grand Total.
Please visit my blog @ http://onlydifferencefaqs.blogspot.in/