Sie sind auf Seite 1von 2

Triggers When there is a change in one table and you want that the connected table should automatically

be updated we use the triggers. Triggers can be done on insert update and delete.You can write triggers on DDL statements which is possible from 2005. When you fire a insert/delete trigger the info doesnot goes directly to the table ,it goes to a temporary table called insert/delete table. The trigger has two options of executing that it is fired before(INSTEAD OF) or after(AFTER) the action. In deleted table, it stores all data that are marked to be deleted. It saves the data till the trigger is getting fired. In Update query it creates both the table.The old query goes to the DELETED table and the new record goes to INSERTED table and then from there it goes to orignal table. The Inserted and Deleted table are called as Pseudo or Magic Table . There can be only one trigger on a table. If you make multiple triggers on one table it will execute whichever comes first. Syntax: create TRIGGER triggername on TABLE NAME [FOR][INSTEAD OF][AFTER] {INSERT / UPDATE / DELETE} as QUERY New Features in SQL SERVER 2005 New functions introduced 1. row_numbers() : To write the row numbers 2. rank (): to rank out the table if there are 12 rows with same id it will write 1 for all record but on 13th it will write 13 3. dense_rank(): same as rank but if there are 12 rows with same id it will write 1 for all record but on 13th it will write 2 4. ntile(number):it makes groups of tuples. Suppose ntile(6) so 6 tuples in each row. Suppose if there are 40 tuples and I am making a group of 6 then it will make 6 groups and 4 tupes are remaining so it will add 1 tuple to each group until the remainders are over. All Funtions in one Query select productname, unitprice, categoryid, row_number() over (order by unitprice desc) 'Row Number', rank() over (order by unitprice desc) 'Rank', dense_rank() over (order by unitprice desc) 'Dense Rank', ntile(9) over (order by unitprice desc) 'nTile' from products Partition by: You have created a groups of same elements as numbers you will find all 1's for 5-6 times, using partition by it gives the row number inside that same numbers. Partion by clause is included in all the row funtions but the effect is visible on the dense_row() and nTile(). Common Table Expr At the runtime we are creating a table.It is the temporary table.Which retrieves single rows at the same time. The processing is slow but comparison between those same tables is possible which helps us to find out the proper outcome. Cursor are the objects of the database which reads one query at that time

Why CTE ? :Bcoz it is a way to use that reads the query at same time Revercisity is the term similar to recusive theory that checks the table one row at a time.A same table calls itself.
with mytable(srno,name) as (select 1,'Lorem Ipsum'), yourtable(no,fname) as (select 'Means Put Anything','its Just a dummpy text where it takes any values') select * from mytable,yourtable

New Datatypes: varchar(max) nvarchar(max) varbinary(max) Transactions You can either start a transaction or end it. It uses keywords CREATE or END. Transaction levels: 1. Read Uncommited:We have a transaction written and we r trying to read a record when im readinging a record someone has already modied the record but has not commited.What happens when he does a rollback-there will be different results for different users. 2. Read Committed:is the default transaction level on 3. Serializable:It is the combination of repeatable read and read committed. 4. Replacable Read:when a user is doing reading of some data that data is already committed by someone else when i do a modification into it someone else are not allowed to read it. Locks help with the problems around in the transaction Types of Locks:-Shared Locks:2 ppl view a data and only 1 is allowed to do a transaction. -Exclusive Lock: only 1 user is allowed to read and write -schema lock: only 1 user can modify a structure at a time for a specific table. -Deadlock

Das könnte Ihnen auch gefallen