I have been migrating a database from SQL Server 2008 to 2012 and there have been problems with triggers that contain RAISERROR, because the syntax has changed between version. Now I could go through and change all of these manually, but that is a whole days work in itself.
Ideally there is a way where I can get a program to go into the triggers and change the RAISERRORs to the new syntax, this will be useful because I will upgrading another server soon and would speed up that process as well.
I have looked into SSMS Add-ins and believe they can directly edit the code within a trigger but the documentation is sparse.
I don't believe it can be done through SQL itself they can only ALTER TRIGGER, whereas I want to actually change the code inside the trigger.
Related
I replaced a proc with an updated version from another db, however the proc had some new changes itself that I overwrote in the process.
Not a huge problem as it's a dev db and I can restore from a backup... except that I will have to go track down where the backup is and restore it and what a pain.
I don't suppose there is any helpful system table in SQL that might show me what the definition was before I changed it? Guessing not, but figured it doesn't hurt to ask.
In short the only way to answer is No.
Sql Server does not track changes to your procedures or other objects, it is not a version control system - unfortunately that's a separate process you (no doubt) have in place. Numerous solutions exist for this that integrate with various repositories such as SVN or Git, such as Redgate Sql Source Control
A little known feature allows you to append a number after the name of a procedure to create your own versions; it's indicated as deprecated in the official documentation but still works in SQL 2019.
There is a table with trigger in our SQL database. (sql server 2014). When updating record from Microsoft SQL Server Management Studio update takes like 1/10 sec. When the record is changed in MS ACCESS (in the form) it takes like 5-6 seconds to update. There is a trigger on that table, but the same operation directly from MSS Management Studio is fast, so it is not a problem with a trigger itself. THe trigger has to insert 1 record to 15 milion records table. I am looking for reasons why the same operation from ACCESS and SQL management studio can take 40 times longer. Any suggestions? Or links to known issues in that topic?
EDIT:
It's ACCESS 2003. It's subform bound to form by ID field. I am edditing simple integer column of record. I use normal connection with my sql server, it's adp project and we just use typical connection for it. I tried to do update from VBA (the same project) but from simple module -> the same effect. So it does not metter if it is eddited from form or update command is send from other module to that table. It still takes long.
To narrow things down I would still suggest to disable the trigger and see if the issue persists.
I have just started an internship in I've had to learn a lot on my own. I'm learning MS SQL Server, but having a strange problem. I have a DB that has four small tables. Each one has a script to drop the table, recreate the table (I've avoided FK dependencies for the time being), and execute a demo query.
Problem 1: When I first started SQL Server Managmenent Studio would execute the script, but one table didn't show up in the Object Explorer. If I tried to execute a demo query from the same .sql file, it executed with no problem. If I tried to access it from another .sql, the table didn't exist. After many times of successfully executing the script, it finally just showed up.
Problem 2: Similar problem. When I updated one table, the changes wouldn't be reflected in queries.
Problem 3: Queries will fail, but if I click execute again with no changes being made, it will usually work correctly.
Problem 4: When I use an alias for a field name, sometimes the alias is recognized and sometimes it isn't. I've literally had single query in which the alias would work in one place, but not work in another and I had to use a fully qualified name.
I've tried the refresh and refresh local cache, but those seem to have no effect. If I exit Management Studio, that seems to usually fix the first two problems.
Am I going nuts or am I just in the dark about some weird specifics of SQL Server?
First of all, when you make a schema change you need to right-click on the "Tables" node for the database in management studio and hit refresh.
If you change a column or something in a table, right-click the table and refresh.
The refresh local cache only updates the intellisense stuff, and the refresh only updates the GUI. If you modify a table with SQL and do not refresh it in the UI, the query can still use the updated table.
If you query fails, you either have a bad query or it's not pointed at the database or connection you think it is.
For aliases, there are places where they will not work (update statements, for example) but if you don't post queries where they don't work we cannot read your mind and tell you what's wrong.
If you have specific queries that are failing, post them.
I have installer to install procedures, scripts, views, etc in SQL server 2005/2008.
Now I want to add a condition in the installer like if there is any error while installing, I want to undo all the changes done in SQL server.
I tried to store the procedures, views, etc which I am changing while installing and reverting them back if I get any error. But am not able to do it the way I want.
Can someone guide me if he had done the same thing?
To specify I am using WIX installer.
Also if someone has tried SMO, it will be of great help.
The simplest and most robust way to handle this is not to use the installer at all. Rather wrap all your SQL into a transaction block. Using this means that if anything fails for any reasons (as part of the SQL) then the transaction will gracefully roll back and all your DB changes will be reverted without you having to implement any more than defining the transaction block on your SQL statement.
Assuming MS SQL more information regarding transactions can be found here:
http://msdn.microsoft.com/en-us/library/ms188929.aspx
Most other mainstream SQL implementation follow a very similar model, but obviously refer to their docs instead.
If you need to trigger "rollback" of the SQL component of your install if some other component of your install fails. Then unfortunately you can't use transactions in this manner. However in this case you could simply call a rollback script that deletes any SP's / tables etc you have added. That said in .NET you can being the SQL transaction handling into the code (i.e. C#) if that is available to you you could use this to wrap up everything.
It can be difficult to rollback an SQL upgrade script, particularly if that script could fail at any point. The problem is that the built-in rollback machinery cannot handle, for example, most DDL statements. Therefore, you would have to implement such rollbacks manually with compensating scripts that undo the changes.
It might be simpler to back-up the database at the outset of the installation and restore it should the installation fail.
In a project of mine the SQL statements that are executed against a SQL Server are failing for some unknown reason. Some of the code is already used in production so debugging it is not an easy task. Therefore I need a way to see in the database itself what SQL statements are used, as the statements are generated at runtime by the project and could be flawed when certain conditions are met.
I therefore considered the possibility to monitor the incoming statements and check myself if I see any flaws.
The database is running on a SQL Server 2005, and I use SQL server management studio express as primary tool to manipulate the database. So my question is, what is the best way to do this?
Seeing how you use the Management Studio Express, I will assume you don't have access to the MSSQL 2005 client tools. If you do, install those, because it includes the SQL profiler which does exactly what you want (and more!). For more info about that one, see msdn.
I found this a while ago, because I was thinking about the exact same thing. I have access to the client tools myself, so I don't really need to yet, but that access is not unlimited (it's through my current job). If you try it out, let me know if it works ;-)
Best way is to fire up profiler, start a trace, save the trace and then rerun the statements