Where is the SQL Server Database Trigger Wizard or Dialog Box? - sql-server

This question is about SQL Server
In the past, I have created a stored procedure that was run on a timely basis by (if I remember correctly) a database trigger. As I recall, there was a wizard (dialog box with "NEXT" buttons) that I used to set things up to have the stored procedure run automatically. That was some time ago. Now when I search for database trigger information online, I find only information about -- creating triggers for when a table is updated or modified. Maybe I am using the wrong terminology and what I am looking for is not a "trigger" at all.

It's not a trigger what you are looking for.
You need to find sql server agent in sql server managment studio, create a new job, add a step, select database and use the command EXEC yourSpName to run the stored procedure.
The in the schedule you can set when you want to run it.

Related

Stored procedure changes not noticed by migrator

Another team in my company is using an unknown-to-me migrator tool.
When I edit a stored procedure in SSMS (ALTER PROCEDURE xyz...), the migrator notices the change, and they push a button to send it on to Test and Prod.
However, if I use a custom C# app to connect to the SQL Server and run the same ALTER, the procedure is changed, but the migrator refuses to see the change. So the workflow stops.
I even changed my app to drop and recreate the procure from scratch, and the migrator still doesn't see the change.
sys.objects clearly has fresh dates in create_date and modify_date.
Any idea what this migrator might be using behind the scenes that might be causing my grief?
The ways the tool might detect changes are an SSMS add-in, DDL trigger, or server-side trace. With the the last 2 methods, SSMS-only changes might be filtered by examining the application name.
Try specifying application name "Microsoft SQL Server Management Studio" in your SqlClient connections string. That should work if schema changes are captured by a filtered DDL trigger or trace.

getting SQL from one database to create a similar database using only SQL

I want to dump one SQL Server database - get all SQL code necessary to create a similar database. I have full online rights to DatabaseA, I can feed it with SQL and get the results back in rows in a table.
I do not have the possibility to use Enterprise Manager, any applications, utilities or the like. I can only feed it with pure SQL.
What I am after is SQL code, like CREATE TABLE and so on. So that I just can paste this into a query and voila - tables, procedures, functions are created in DatabaseB.
I will not copy the data.
This partly does what I want, it gives me procedures and functions:
Select object_Name(object_ID),definition from sys.SQL_Modules
But not for tables.
You can use the command line or you can create a stored procedure to create a back up, then use that backup to create a new database. I have used the command line often. Here is a previous Stack question that has a command line example and a link to a stored procedure example.
You can generate scripts in SQL Server Management Studio for an entire database or specific database objects.
To do this, right click the database then select Tasks then select Generate Scripts.
It will then open a wizard which will give you the option to choose to script the full database or just specific database objects.

SQL Server Mangement Studio Alter Script (2005)

Is it possible to generated ALTER sql script from the changes you perform in Server Studio. This is possible in different tools for mysql, basically you get the log of executed statements. Is similar thing possible here, or how do you go about finding out what the modification (ALTER) script is?
Thanks.
-- MB
You will be able to auto generate change scripts in SSMS. Take a look at this article, I believe it might be what you are looking for. http://www.mssqltips.com/tip.asp?tip=1723
from the article
As a part of my best practices, I always save the T-SQL scripts used for creation and modification of objects in SQL Server. When creating and modifying tables using SQL Server Management Studio designer it is easy to right click in the designer and select "Generate Change Script...", but is there a way to automatically script the creation and/or modification of tables made through of SQL Server Management Studio (SSMS) designer? This tip shows you an option that exists within SSMS to automatically generate these scripts for all table changes when using the table designer.
If you're altering a table (by right-clicking and selecting Design, then there is a button named Generate Change Script on the Table Designer toolbar.
If you're talking about changes made in a properties window, there is a script button at the top of each of those that can generate scripts for changes you make through the UI.
Not sure about SQL Server 2005, but in SQL Server Management Studio 2008 and later, you can definitely do this.
When you modify a table in the table designer (right-click on a table in your Object Explorer and pick "Design" from the menu), you can have SSMS generate the ALTER script for you by right-clicking in the designer and choosing "Generate Change Script":

SQL Server replication without deletes?

Is there a way to replicate a sql server database but not push out deletes to the subscribers?
You don't mention which version of SQL Server you're running, but Andy Warren wrote an article on configuring INSERT, UPDATE, and DELETE behaviour in SQL Server 2005. You can configure this through the GUI, using his instructions:
http://www.sqlservercentral.com/articles/Replication/3202/
It's tempting to 'intervene' in a normal replication and 'disarm' the subscriber's side delete stored procedures, but this leaves no option to recover from replication failure. If the replication tries to recover, a reinitialize may be needed and this will drop any 'stale' data that the replication agent considers deleted.
An alternative is to use a normal replication, and use a script that generates insert and update triggers on all tables in the subscriber database, that insert/update that data into yet a third database. This way the third DB will collect all the data that ever existed, the second DB can re-initialize it's subscription if it needs to (when you do, just remember that bulk inserts don't call the insert trigger and check for new data and add it to the third DB), and the first DB doesn't have to perform the extra work that the triggers are.
Do this....Drop the article. Create a new storedprocedure in the corresponding database that mimicks the system store procedure (sp_del...) and contains the same parameter but does nothing. Add the article again...and set the delete store procedure under the article's properties to the new delete stored procedure that you created....
Or you can select Do not replicate Delete Statements....I think that works but i haven't tried it.

SQL Server 2005 Change Auditing

Is there a built in way in SQL Server 2005 to audit things specifically like deleting a stored procedure? Is there a history table that I can query? We have a mystery sproc that has disappeared a few times now.
You can build this using DDL triggers:
http://msdn.microsoft.com/en-us/library/ms190989.aspx
Only if you use DDL triggers or use profiler to trace text "%DROP%PROC%procname%"
Note that in SQL Server 2008 they also now have AUDIT to replace Profiler Traces for auding activities. It is similar but has its own configuration UI and UI to view results
You can setup a profiler trace to capture the Audit Schema Object Management event and filter based on the database name you care about. Any time an object in the schema is created, dropped, edited it will fire an event in profiler that includes the person who did the change and the name of the stored procedure.
You will want at least these profiler columns:
ApplicationName - name of app user was running when they made change
DatabaseName - Databse containing the object changed
EventSubClass - Type of action shows Alter, Modify, Drop, Create etc
LoginName - user making change
ObjectName - object affected
[late one but adds details on how to see who made the change even before auditing system is put into place]
Others have already covered different ways you can start auditing data in order to monitor future changes but if you originally didn’t have any auditing system in place then it’s very difficult to find out who did what and when historically.
Only option is to try reading transaction log assuming database is in full recovery mode. Problem is that this is not supported by default. Options are:
Third party tools such as ApexSQL Log or Quest Toad
Undocumented functions such as DBCC LOG or fn_dblog
See these topics for more details:
How to view transaction log in SQL Server 2008
SQL Server Transaction Log Explorer/Analyzer
How to see query history in SQL Server Management Studio
I agree. It can be the SQL Server profiler with filters. The DDL triggers existed in SQL Server.
You could create something like this:
CREATE TRIGGER ddl_drop_procedure
ON DATABASE
FOR DROP_PROCEDURE
AS
RAISERROR ('You deleted a stored procedure',10, 1)
GO
The other option is to use third party tools like Auto Audit from codeplex, or apexSQL trigger.

Resources