Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, May 15, 2011

View in Sql Server


View in Sql Server
  • ·        View is a virtual table
  • ·        It s contains columns and data in different table
  • ·        View does not contain any data directly. Its a set of select query
Table 1

Sno
Sname
Table 2
Sno
Lname

                              
View_table1_table2

Sname
Lname

Above drawing table 1 and table we will write join query after we can create view
Syntax
CREATE VIEW JS_VIEW_NAME
AS
[SELECT STATEMENT]
Why we are use View ?
·        View is used for security mechanism .if you restricted particular column for users .
Sql Server Syntex for View
CREATE VIEW
CREATE VIEW JS_VIEW
AS
SELECT *FROM STUD A,LIB L WHERE A.SNO=L.SON
ALTER VIEW
ALTER VIEW JS_VIEW
AS
SELECT *FROM STUDENTTABLE  A,LIB L WHERE A.SNO=L.SON

SELECT VIEW
SELECT*FROM JS_VIEW
DROP VIEW:
DROP VIEW JS_VIEW        

Trigger Interview Questions

How many types of triggers are there in Sql Server 2005?
There are two types of triggers
• Data Manipulation language (DML) triggers
• Data Definition language (DDL) triggers
DML triggers (implementation) will run when INSERT, UPDATE, or DELETE statements modify data in a specified table or view.
DDL triggers will run in response to DDL events that occur on the server such as creating, altering, or dropping an object, are used for database administration tasks
What are the different modes of firing triggers?
After Trigger: An AFTER trigger fires after SQL Server completes all actions successfully
Instead of Triggers: An INSTEAD OF trigger causes SQL Server to execute the code in the trigger instead of the operation that caused the trigger to fire.

Trigger In Sql Server


Trigger In Sql Server
·        Trigger is a special kind of Store procedure
·        Modifications to the table are made using INSERT,UPDATE OR DELETE  trigger will run
·        It is automatically run
·        Triggers prevent incorrect , unauthorized, or inconsistent changes to data.

Syntax in Trigger:

CREATE TRIGGER trigger_name ON table_name

FOR [INSERT/UPDATE/DELETE] AS

IF UPDATE(column_name)

[{AND/OR} UPDATE(COLUMN_NAME)...]

{ sql_statements }

Trigger Rules:

·        A table can have only three triggers action per table : UPDATE ,INSERT,DELETE.
·        Only table owners can create and drop triggers for the table.This permission cannot be transferred.
·        A trigger cannot be created on a view or a temporary table but triggers can reference them.
·        They can be used to help ensure the relational integrity of database.On dropping a table all triggers associated to the triggers are automatically dropped .

INSERT TRIGGER
·        When an INSERT trigger statement is executed ,new rows are added to the trigger table and to the inserted table at the same time.
·        The inserted table allows to compare the INSERTED rows in the table to the rows in the inserted table.
 DELETE TRIGGER
·        When a DELETE trigger statement is executed ,rows are deleted from the table and are placed in a special table called deleted table.
UPDATE TRIGGER
When an UPDATE statement is executed on a table that has an UPDATE trigger,