solving sql server problems for millions of dbas and developers since 2006



SQL Server DBA Tips SQL Server Developer Tips SQL Server Business Intelligence Tips SQL Server Career Tips SQL Server Whitepapers SQL Server Tools SQL Server Webcasts SQL Server Questions and Answers SQL Server Questions and Answers





SQL Product Highlight

Idera - SQL diagnostic manager

SQL diagnostic manager is a powerful performance monitoring and diagnostics solution that proactively alerts administrators to health, performance or availability problems within their SQL Server environment via a central console or mobile device. SQL diagnostic manager minimizes costly server downtime by providing agent-less, real-time monitoring and customizable alerting for fast diagnosis and remediation of SQL Server performance and availability problems. SQL diagnostic manager also provides a 'community' environment where, using Idera's IntelliFeed(TM) technology DBAs form a community to collaborate to quickly resolve problems, perform maintenance and capture best practices.

Learn more!









write a trigger for stoping dml operations at particular time

Asked 2/11/2012 5:39:29 AM by kareemulla



Answered 2/11/2012 7:55:44 AM by Ray Barley (0) vote answer is useful vote answer is NOT useful

As an alternative you could set the database to read only for the time you don't want any dml operations then set it back to read write when it's okay for dml operations.  See this tip for the details on setting a database to read only and read write: http://www.mssqltips.com/sqlservertip/1921/best-practices-for-working-with-read-only-databases-in-sql-server/

 


Answered 2/14/2012 12:51:35 PM by Raymond Barley (0) vote answer is useful vote answer is NOT useful

Here's an example where you put a trigger on each table that will stop dml whenever a certain value exists in a settings table.

 

-- create a table where we can specify a row with disable_dml = 1 when we don't want to allow any dml

create table dbo.settings

(

disable_dmlbit

)

go

 

-- disable dml

insert into dbo.settings values (1)

go

 

 

-- create a table for testing

create table dbo.test

(

idint

)

go

 

-- create a trigger to rollback transaction if dml is disabled

create trigger dbo.test_dml_trigger

on dbo.test

for insert, update, delete

as

begin

if exists (select 'x' from dbo.settings where disable_dml = 1)

begin

raiserror('DML is disabled',16,1)

rollback transaction

return

end

end

go

 

-- test dml disabled; will display error:

-- Msg 50000, Level 16, State 1, Procedure test_dml_trigger, Line 8

-- DML is disabled

-- Msg 3609, Level 16, State 1, Line 2

-- The transaction ended in the trigger. The batch has been aborted.

begin transaction

insert into dbo.test default values

commit transaction

 

 



Post an Answer

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email   Notify for updates
Comments
*Enter Code refresh code


 
Sponsor Information
Find and fix SQL Server problems before they happen - SQL diagnostic manager now with predictive analysis!

SQL Monitor – For database professionals who need results on Day One. Try it online.

What grade do you think your SQL Servers get? Find out with a SQL Server Health Check consultant.

Free Trial: Get Proactive Insight with Spotlight® for SQL Server Enterprise.

Solving SQL Server problems for millions of DBAs and Devs since 2006. Join now.

Free Learning - Introduction to SQL Azure Delivered by Herve Roggero on Wednesday, June 13 @ 3:00 PM EST


Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | user groups
Some names and products listed are the registered trademarks of their respective owners.


Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com