Can we get Altered stored procedure - sql-server

Hi by mistake I've altered one stored procedure and is there any chance to get that old procedure?
Thank you

There is no reason whatsoever to not put your database in source control and treat it like any other code. You should NEVER make a change to a database without a source control script. This means never ever using the GUI to make database changes.
The only way to get back what you replaced is to restore a backup or if you have the other version on a another server, then script it and re-run on the server you you changed.
Yes fixing your source control problem is an emergency, you and your team should not write anymore code of any kind until this is done.

Restore a backup of the affected database onto another server to get the old procedure's code, then copy just that code over.
If you don't have a spare server, you can restore the database to a different database on the same server. (create a new database, then restore the backup to that - just pay attention that you're restoring onto your new/temporary database, then delete that database when you're finished)
Red-Gate has SQL log rescue which might have helped (it's for SQL2000), but there might be other solutions available.

Related

Is there any possible way to restore database with only merge or insert options instead of deleting or replacing data (SQL Server 2014)

I used the following command for restoring a database:
RESTORE DATABASE TorqueNet
FROM DISK = 'C:\Backup.bak';
GO
This command deletes the existing data and performs a complete data replacement.
Instead of that, I want to append new data and replace existing records if there are any changes but keep existing data.
If I understand you, no you cannot. A database restore will overwrite the destination.
It sounds like you are wanting to merge one database into another, which can be done with 3rd party tools.
You would need to
Restore the backup to another database
Merge the newly restored database into the current database.
If this is a task that you need to repeat, then you could probably create an SSIS package to help you automate the process.
If you have a search for SQL Merge tools, or look at this question
A restore is replacing the database, its not running any kinda of insert or update transact sql it really is just overwriting the database.

Stored Procedure to restore SQL Server database from the backup

I'm looking for a procedure which would help to restore my database from the backups. I have googled and couldn't find the extract one which I was looking for. Basically I have 2 kind backups files (some backups with .mdf and .log file and some backups around 30 logical files). Would like to pass 2 argument to the procedure during the execution, backup name and the old and/new database name. Could you please advise me putting up this procedure?
You don't need a stored procedure to restore a database and nothing exists within the product by default. You can certainly write one customized for you specific needs if you like.
Details on RESTORE statement is here https://learn.microsoft.com/en-us/sql/t-sql/statements/restore-statements-transact-sql Check it out, try it then come back if you have further questions.
Specific to your ask above, you don't need to specify old DB name if you want to use an existing backup to restore to a new DB name. This is basically a copy operation. The following is a sample of what the script might look like. You should fully understand how the RESTORE statement works (link above) and modify as appropriate for your needs.
-- Assuming your original backup was on Pubs database
RESTORE DATABASE Bars
FROM PubsBackups
WITH MOVE 'Pubs_Data' TO 'D:\SQLServer\bars.mdf',
MOVE 'Pubs_Log' TO 'L:\SQLServer\bars.ldf';

Remove historical Stored Procedures from SQL Server backup

A developer has included a DB password within a stored procedure (rolls eyes). We include a backup of this database with our setup application for new customers. We've updated the stored procedure, but the password is still visible in plain text within the backup file as this includes both the current stored procedure and the original one.
We've cleared transaction history and recreated the log file, but these don't seem to affect historical stored procedure code. Is there some way of removing this from the DB backup?
Thanks very much in advance for any suggestions! We've hunted around and drawn a blank so far.
You could re-create the full db. SSMS will support you under Tasks -> Generate Scripts... But this can be quite a big work to do...
If you are developing with Visual Studio You could think about a data base project to set your database under Source Control and get a scripted master. This makes it easier to re-create the full database and offers many other benefits. Other IDEs will support this too - probably.
You could try to set the db to single-user-mode, set its backup mode to simple, shrink the log file to smallest, shrink database files to smallest and drive a full backup. I've never had this problem, but I'd assume, that doing so, all residues should disappear...
Good luck!

Determne if SQL Server database restored

I need to check if a content database for SharePoint has been restored (as some point in the past).
Are there any log file entries - in SharePoint or SQL Server - I can check for to determine this? Or any other approach (apart from asking someone)?
If you want to know when was the last time a database was restored, look into msdb.dbo.restorehistory.
If you want to know if a current restore operation is complete, check the database status in sys.databases.
You could try connecting to it. You won't be able to if its in the middle of a restore.

Can you do a partial restore to an ms crm db?

Is there any way (3rd party product or other method) to do a partial restore to ms crm?
Say a user accidentially deleted an account. Is there anyway to restore just that single account and corresponding notes, activities etc?
We limit users' permissions but inevitably they will have permission to delete some things and will want to get that item from a backup.
Right now the only method I can think of is to restore the .bak file to another db and write a bunch of code using the sdk to re-create the items. Are there any other options?
Red Gate has a tool which will let you restore just certain objects from a database.
Idera has this new virtual database tool where you basically mount the backup as a SQL Server database.
Full disclosure - I haven't used either for this kind of thing - I've always either used audit trails or restored the database and extracted the data manually.
You are correct in that you can only restore to a different database and work from there.
You could then use something like Red Gate data compare to extract the desired rows (14 day trial, but it's worth it's weight in SO Rep anyway)
To be honest, I'd go with
Right now the only method I can think of is to restore the .bak file to another db and write a bunch of code using the sdk to re-create the items.
After all, 'Its the only way to be sure....', not to mention the (extremely) vague chance of another record being created with the same GUID, which would cause assorted 'bad stuff' to happen.
Yes, a small number, but still more than 0...

Resources