You are on page 1of 2

1.Difference between Constraints and Triggers S.

No 1 Constraints Triggers

Once we define some constraint in It will be stored as separate object a table they will be stored along with table defination Constraints will do memory location to table comparison. In the order of precedence first Constraints will be fired Performance wise Constraints will not give best performance because memeory location to table comparision is slower than table to table comparison. Constraints cannot start a chain reaction as like triggers - for instance each delete, update action etc. can trigger off another function Triggers will do table to table comparison.For this triggers will use magic tables(inserted,deleted). In the order of precedence only after Constraints is fired,then only Triggers will be fired Performance wise triggers will give best performance because table to table comparison is faster than memeory location to table comparision. Triggers are used to carry out tasks which cant be done using constraints. For eg:-A change in the "sal" column of a table should change the "tax" column in another table.This cant be done using constraints.It has to be done using triggers.Thats where the importance of triggers lie. Trigger is used for table Trigger is a user defined business rule for which user is responasible for logic for business rule

6 7

Constraint is used for column Constraints are predefined business rules in which all the organisations follow this constraints without any modification. Constraints are used to maintain the integrity and atomicity of database .In other words it can be said they are used to prevent invalid data entry . the main 5 constraints are NOT NULL,PRIMARY KEY,FOREIGN KEY,UNIQUE KEY and CHECK

Triggers are bascically stored procedures which automaticallly fired when any insert,update or delete is issued on table

2.Difference between Cast and Convert in SQL Server

S.No 1 2

Cast Cast is ANSII Standard Cast cannot be used for Formatting Purposes. Cast cannot convert a datetime to specific format Usage of CAST: USE Sample GO SELECT SUBSTRING(Name, 1, 30) AS ProductName, ListPrice FROM Production.Product WHERE CAST(ListPrice AS int) LIKE '3%'; GO

Convert Convert is Specific to SQL SERVER Convert can be used for Formatting Purposes.For example Select convert (varchar, datetime, 101) Convert can be used to convert a datetime to specific format Usage of CONVERT: USE Sample GO SELECT SUBSTRING(Name, 1, 30) AS ProductName, ListPrice FROM Production.Product WHERE CAST(int, ListPrice) LIKE '3%'; GO

3 4

3.Difference between CUBE and ROLLUP

S.No 1

CUBE It is an additional switch to GROUP BY clause. It can be applied to all aggregation functions to return cross tabular result sets. Produces all possible combinations of subtotals specified in GROUP BY clause and a Grand Total.

ROLLUP It is an extension to GROUP BY clause. Its used to extract statistical and summarized information from result sets. It creates groupings and then applies aggregation functions on them. Produces only some possible subtotal combinations

Please visit my blog @ http://onlydifferencefaqs.blogspot.in/

You might also like