You are on page 1of 1

(A) DML TRIGGERS

• CREATE TRIGGER [ schema_name . ]trigger_name


ON { table | view }
{ FOR | AFTER}
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
AS { sql_statement [ ; ] }
Example :
Create trigger testdb.insertTG
on Inventory AFTER INSERT
AS
SELECT “Record Inserted” ;

(B) INSTEAD OF FEATURE


CREATE TRIGGER
Testdb.rec_delete
ON Inventory
INSTEAD OF DELETE
AS
BEGIN
   PRINT '<< You have tried to delete the record in Sorry! You cannot delete the record..>>'
END
(C) DDL Triggers
CREATE TRIGGER Tr_DDL_DROPTABLE
ON DATABASE
FOR DROP_TABLE
AS
BEGIN
  SET NOCOUNT ON
  SET XACT_ABORT ON
  ROLLBACK
  PRINT '<< You cannot drop the table >>'
END

(D) Administration
CREATE USER user_name 
[ { { FOR | FROM } { LOGIN login_name | WITHOUT LOGIN ]   
 [ WITH DEFAULT_SCHEMA =schema_name ]
• To create user with windows authentication
CREATE LOGIN student WITH PASSWORD = ‘S#123';
To create a SQL Server login that uses Windows Authentication (SQL Server Management Studio)
1. In SQL Server Management Studio, open Object Explorer and expand the folder of the server instance in which to
create the new login.
2. Right-click the Security folder, point to New, and then click Login.
3. On the General page, enter the name of a Windows user in the Login name box.
4. Select Windows Authentication.
5. Click OK.
• Contd.
• ALTER USER student WITH DEFAULT_SCHEMA=testdb;
• DROP USER student;
• GRANT EXECUTE ON testdb.del_rec TO student;
• DENY DELETE ON testdb.Inventory TO student;
(E) DEPLOYMENT - BACKUP AND RESTORE
• Your simplest backup strategy is to run, at regular intervals, the following SQL Server backup command, which will
perform a full backup of the database:
ALTER DATABASE AdventureWorks 
SET RECOVERY SIMPLE;
BACKUP DATABASE AdventureWorks 
TO DISK = 'C:\Backups\AdventureWorks.BAK‘;
• RESTORE VERIFYONLY
FROM DISK = 'C:\backups\Adventureworks.bak'

You might also like