Monday, December 10, 2012

How To Create A Trigger.


Trigger is procedural code that is automatically executed in response to certain events on a specific table in a database. Triggers can restrict access to specific data, perform logging, or audit data modifications.

Triggers are of 3 types in SQL Server 2005:

1. DML Triggers
   - AFTER Triggers
   - INSTEAD OF Triggers { INSERT, UPDATE, and DELETE }
2. DDL Triggers {if any schema change.}
3. CLR Triggers


Create trigger Delete_TrigerName
on ReferanceTable
for Delete
as

--Checking for Table exist.
--if Table not exist then create a table with same schema of operation table

if NOT EXISTS(SELECT * FROM information_schema.tables
                              WHERE TABLE_CATALOG = 'DATABASE-NAME'
                              AND table_name = 'Backup-TABLE-NAME')
begin
-- Copy full table with creating table of copied table schema                      
     select * into  Backup-TABLE-NAME from deleted

--Set Identity column Off. Otherwise we will not able to track the                                                                                                                                previous position of table.
     SET IDENTITY_INSERT [Backup-TABLE-NAME ] off
end

else

begin
       INSERT INTO Backup-TABLE-NAME ([Column1],[ Column2],[ Column3])
       SELECT [Column1],[ Column2],[ Column3]
       FROM deleted
end


--select * from Backup-TABLE-NAME
--select * from AgentMaster
--delete from AgentMaster where Ag_ApplNo=22

How to Create Cursor




declare @tempt table
(
ID int null,
Name varchar(100) null
)

DECLARE @vendor_id int, @vendor_name nvarchar(50),
    @message varchar(80), @product nvarchar(50);

PRINT '-------- Vendor Products Report --------';


-- Declare Cursor – untill it deallocate
-- You Con’t declare another cursor with same name.

DECLARE vendor_cursor CURSOR FOR
SELECT ID,Ag_Fname
from AgentMaster

OPEN vendor_cursor

FETCH NEXT FROM vendor_cursor
INTO @vendor_id, @vendor_name

WHILE @@FETCH_STATUS = 0
BEGIN
   
    SELECT @message = '----- Vendor: ' +
        @vendor_name

    PRINT @message
    insert INTO @tempt values (@vendor_id, @vendor_name)
   
    FETCH NEXT FROM vendor_cursor
    INTO @vendor_id, @vendor_name
END
CLOSE vendor_cursor;

select * from @tempt
-- Deallocate Cursor
DEALLOCATE vendor_cursor;

Sunday, December 9, 2012

How To Buy A Blogspot Domain



1.          First  you login to blogspot.com
2.          Then if you have account go to the dashboard

3.          Click on the Setting. And select About Our New Look and click
4.          Choose About URLs from left panel and click
5.       Click custom domain. In newly open page.
6.       Choose radio button Buy a custom domain through Blogger.



7.       Click  Google Checkout New window icon link in this page.

8.       Google Wallet logging page will open. Login with your user name and password.


9.       Now You will get the shopping page. Fill data with correct data including Payment method.

 

 

 


Friday, December 7, 2012

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...