# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?

Difference between Instead Of and Before Triggers:
INSTEAD OF triggers override the standard actions of the triggering statement: an INSERT, UPDATE, or DELETE. An INSTEAD OF trigger can be defined to perform error or value checking on one or more columns, and then perform additional actions before inserting the record.
BEFORE triggers are usually used when validation needs to take place before accepting the change. They run before any change is made to the database.

2. What is(are) the difference(s) between UDF and stored procedure?

Difference between UDF and Stored Procedure:
>> UDF must return a value but Stored Procedure may or may not return a value.
>> UDF will allow only input parameters, doesn't support output parameters. But Stored Procedure can have both input and output parameters.
>> Stored Procedures can't be called from a function but Stored Procedures can call functions.

# data[].attributes.body
1)What is the difference between instead of trigger and
before trigger?

Instead of trigger it allow you to override functionality,or implement functionality that otherwise isn't supported,it also fire before an insert,update,or delete operation and replace the original operation.

Before trigger cannot override a view and it can update and insert an object or table.

2)What is(are) the difference(s) between UDF and stored
procedure?

UDF:

-can be used in join clause as result
-allow only selected statemend and Not allow to use dml statement
-Function must return value

Stored procedure:

-procedures can't be used in joinclause.
-can have dml statement like insert,update delete.
-May or may not return values

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger ?
INSTEAD OF triggers replace the original operation and fire before an insert, update or delete operation. For example, if an INSTEAD OF DELETE trigger exists on a table, when a client deletes a record, the trigger code will fire and then control will return to the client. And BEFORE triggers are to be applied before any changes caused by the actual update of the subject table are applied to the database. It also specifies that the triggered action of the trigger will not cause other triggers to be activated.

2. What is (are) the difference(s) between UDF and stored procedure?
UDF must return a value but stored procedure may or may not return values. Stored procedures can't be called from a function (UDF) but stored procedures can call functions. Functions can be called from a SELECT statement. On the other hand, procedures can't be called from SELECT/WHERE/HAVING and so on statements. EXECUTE/EXEC statement can be used to CALL/EXECUTE stored procedure.

# data[].attributes.headline
Mohamad Danial b. Abdul Jasheer 1112701647

# data[].attributes.subject
Mohamad Danial b. Abdul Jasheer 1112701647

# data[].attributes.body
1. AFTER trigger fires after a DML operation. INSTEAD OF trigger fires instead of a DML operation.Big difference. INSTEAD OF allows you to override functionality, or implement functionality that otherwise isn't supported. The common place I use it is to create updateable views. Sometimes a view may not be key preserved, but as the designer you may know which base table(s) you want to update so you can do it by writing specific logic to do the update behind the scenes. An alternative is just to write a stored procedure and force the developers to call those procedures instead of performing DML on a view, but DML on views is a nice abstraction, in my opinion, because developers can treat views like tables. That is how relational design is meant to be.

2.  Stored Procedure

A Stored Procedure is nothing more than prepared SQL code that you save so you can reuse the code over and over again. So if you think about a query that you write over and over again, instead of having to write that query each time you would save it as a Stored Procedure and then just call the Stored Procedure to execute the SQL code that you saved as part of the Stored Procedure.

User Defined Functions

Like functions in programming languages, SQL Server User Defined Functions are routines that accept parameters, perform an action such as a complex calculation, and returns the result of that action as a value. The return value can either be a single scalar value or a result set.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of Triggers
-Instead of triggers allows you to override functionality, or implement functionality that otherwise isn't supported.
-Instead of triggers fire before an insert, update, or delete operation and  replace the original operation.
-It will often be used to slightly modify the new values being written to a table.
-Sometimes necessary to refresh the record image after an update has been performed.

Before Triggers
-Fired before an insert, update, or delete operation.
-Instead of triggers are the only triggers allowed to modify the same record that the client application currently has locked, attempts to do so with a BEFORE trigger will result in record locking errors.

2. What is(are) the difference(s) between UDF and stored procedure?
- Procedures can have input/output parameters for it whereas functions can have only input parameters.
- Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
- Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?

Instead of trigger -   allows you to override functionality, or implement functionality that otherwise isn't supported. The common place I use it is to create updateable views.
BEFORE triggers -  are usually used when validation needs to take place before accepting the change. They run before any change is made to the database.

2. What is(are) the difference(s) between UDF and stored procedure?

- Procedure can return zero or n values whereas function can return one value
which is mandatory.
- Procedures can have input/output parameters for it whereas functions can have
only input parameters.
- Procedure allows select as well as DML statement in it whereas function allows
only select statement in it.
- Procedures can not be utilized in a select statement whereas function can be
embedded in a select statement.
- 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.

# data[].attributes.body
1. What is the difference between instead of trigger and
before trigger?

Instead of trigger replaces the data-modification statement and instruct SQL Server to perform an alternative action. It is similar to before trigger in that they are invoked before the data modification takes place, but a true before trigger would perform the trigger action, then perform the requested modification.

2. What is(are) the difference(s) between UDF and stored
procedure?

i. Stored procedures can accept input, output and input type parameters for it.
UDF can accept only input type parameters.

ii. Stored procdures can create a table but can’t return table.
UDF can create, update and delete the table variable. It can return a table.

iii. In Stored procedures we can use transaction statements. We can’t use in UDF.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of Triggers - works on view and execute only one update, insert, and delete per view
Before Triggers - Work on base tables and actions in trigger will be performed first before the modification made

2. What is(are) the difference(s) between UDF and stored procedure?
UDF - return only one value, will allow only Select statements and can be used in join clause as a result set
Stored Procedure - may or may not return a value, can have select statements as well as DML statements(insert, update, delete) and can't be used in join clause

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger ?
INSTEAD OF triggers occur before an insert,update and delete operation. It is useful when handling with some modification of changes by the client before actually posting the update operation.
BEFORE triggers can be used to update or validate record values before they are saved to the database.They run before any change is made to the database. it can't be use on any type of view.

2. What is (are) the difference(s) between UDF and stored procedure?
UDF
-Function must return a value.
-It will allow only input parameters, doesn't support output parameters.
-Will allow only Select statements, it will not allow us to use DML statements.
Store Procedure
-Stored Procedure may or not return values.
-It can have both input and output parameters.
-Can have DML statements such as insert, update and delete.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
INSTEAD OF trigger fires when performs a DML operation on the view and allows to override functionality. Hence, make the view update-able.
BEFORE trigger fires after modification are done and it can't be use on any type of view.

2. What is (are) the difference(s) between UDF and stored procedure?
UDF :
- Only allows SELECT statement and does not allows to use DML statements
- Function must return a value
- Can be used in join clause as a result set
Stored Procedure :
- Allows SELECT statement and DML statements as well
- May or may not return values
- Procedures can't be used in join clause

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of triggers fire before an insert, update or delete operation. Instead of triggers are useful when you want to modify the changes made by the client before actually posting the update operation. Before trigger, fires before an update or insert. Values that are being updated or inserted can be modified before the database is actually modified. Before triggers can also be used to cause other non-database operations to be activated through user-defined functions.
2. What is(are) the difference(s) between UDF and stored procedure?
Stored Procedure:
-may or not return values
-can have DML statements(insert,delete,update)
-it can have both input and output parameters
UDF:
-must return a value
-DML statements are not allowed
-only input parameters are allowed

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of trigger execute update, insert or delete once only on view while before trigger able to execute on source table unlimited times.

2. What is(are) the difference(s) between UDF and stored procedure?
UDF return one and only one value by using select command while stored procedure may return more than one values by using call command.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
- the triggered actions for before trigger are activated for each row in the set of affected rows before the trigger event executes.
- the triggered actions for instead of trigger are activated for each row in the set of affected rows instead of executing the trigger event.

2. What is(are) the difference(s) between UDF and stored procedure?
- stored procedure can return no value or more than one value while UDF is mandatory to return one value.
- stored procedure have input or output parameters for it while UDF can only have input parameters.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?

Instead of trigger fires when there is action done on a view. The trigger action will effects the source table.
Before trigger fires before an action makes change on source table. Hence some modification or checking action can be applied on the target data.

2. What is(are) the difference(s) between UDF and stored procedure?
i) UDF can only return one value or one table. Stored procedure can return more than one value (or a table).
ii) UDF can only be invoked by SELECT statement. Stored procedure can be invoked by CALL keyword.
iii) UDF is compiled whenever it's invoked. Stored procedure only compiles once.
iv) UDF must return at least a value. Stored procedure may or may not return value.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
INSTEAD OF Trigger is used on views that  you can override INSERT, UPDATE, and DELETE operation on view that you create but BEFORE trigger cannot override on a view and it can update or insert an object or table.

2. What is(are) the difference(s) between UDF and stored procedure?
store procedure - i) May or not return values
ii) Cannot use in join clause
iii) allow select statement as DML statement such as                      insert,update and delete.
UDF - i) Must return values
ii) Can be used in join clause as result set
iii) will only allow Select statement but DML statement is not allowed.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of trigger - instead of trigger only works on views but it allow SQL
operation (insert, delete, update) on the base table rather than
the view itself.
Before trigger - Before trigger works on base table allow SQL operation (insert,
delete, update) on the base table after trigger fire.

2. What is(are) the difference(s) between UDF and stored procedure?
UDF - user define function must return a values and cannot call store procedure
from function.
Store procedure - stored procedure may or may not return values and can call
function from store procedure.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of trigger works on view(without check option) and it effects the source table while before trigger works on source table and can be used to check the format of table before the table get modified.

2. What is(are) the difference(s) between UDF and stored procedure?
- UDF must return value whereas stored procedure may or may not return value.
- UDF compiled every time when it is called, while stored procedure only compiles once and can be used whenever it is called.
- UDF must work with SELECT statement while stored procedure works with the keyword CALL.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
Instead of trigger works only on view but not the base table. Before trigger works on base table.

2. What is(are) the difference(s) between UDF and stored procedure?
a) Stored procedure can only called using CALL keyword, whereas UDF can only called from using select, where or having clause.
b) Stored proedure accept input, output, and inout type parameters, whereas UDF only accept input type parameters.
c)  Stored procedure may or may not return values, whereas UDF must return a value.

# data[].attributes.body
1. What is the difference between instead of trigger and before trigger?
I)Instead of trigger:
>>Used only on views, not base tables.
>>Can overcome the problem of insert/update on view if the base table of view have constraint not null attribute.
>>Can overcome the problem of/insert/update/delete on view that combine two or more tables.
II) Before trigger
>>Work on base tables, not views.
>>Actions in trigger will be performed first before the modification made on base table.

2. What is(are) the difference(s) between UDF and stored procedure?
I)UDF
>>Invoked  using SELECT command
>>Able to return single value, a row, a column or a table. (Single result only)
>>must return result.
>>can not perform DML statement
II)Stored Procedure
>>Invoked using CALL command
>>may or may not return result.
>>may return multiple values.

# data[].attributes.body
Answer the following questions:
1. What is the difference between instead of trigger and
before trigger?
INSTEAD OF
Can use view as the subject table.
The trigger is activated to override the actions(constraints) from the base table.
The trigger can also perform additional actions before modifications made on the table.

BEFORE
Not allow to use view as the subject table.
Trigger is activated and executed before modifications made on the table.

2. What is(are) the difference(s) between UDF and stored
procedure?
UDF
Return only one value
Can only contain one parameter (input)
Able to used in views, stored procedure and other UDFs

STORED PROCEDURE
Return values are optional and can return many values
Can contains many parameters (input/output)

# data[].attributes.headline
Share your answers here.  Do include your student ID when answering. Thank you.

# data[].attributes.subject
Share your answers here.  Do include your student ID when answering. Thank you.