Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Silkroad Online > SRO Private Server
You last visited: Today at 07:01

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Guide]Restore a table without restoring the whole database

Discussion on [Guide]Restore a table without restoring the whole database within the SRO Private Server forum part of the Silkroad Online category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Feb 2009
Posts: 173
Received Thanks: 14
[Guide]Restore a table without restoring the whole database

In playing with my test server I've fucked up a few times as I'm sure some of you have as well.

Here's how you can restore an entire table or only parts of a table without restoring the entire database.

This is best used on _Ref<X> tables, tables that are only ever changed if you do it yourself. Dynamic tables like _Items or _Char are subject to problems if you use this kind of query and I don't recommend it and won't help you if you do it and something breaks.

First

ALWAYS MAKE A BACKUP BEFORE YOU RUN ANY QUERY THAT MODIFIES DATA IN YOUR DATABASE

Should go without saying.

Second

This method would probably give professional DBAs a heart attack. But it works in specific instances as mentioned above, on static tables.

Here it is:

Code:
USE DATABASE --Replace with whatever db youre updating eg: SRO_VT_SHARD
GO
SET IDENTITY_INSERT TableName OFF --Replace with the table youre updating eg: _RefSkill
MERGE DATABASE.dbo.TableName dest --Replace with the multipart reference to your table eg: SRO_VT_SHARD.dbo._RefSkill
USING (SELECT * FROM SRO_VT_SHARD_BACKUP.dbo.TableName) AS src --Replace with the multipart reference to your backup table eg: SRO_VT_SHARD_BACKUP.dbo._RefSkill
	ON dest.UniqueIdentifier = src.UniqueIdentifier --Replace with the unique identifier columns in your table. (The one that is auto incremented and that you aren't allowed to change) In the case of _RefSkill it's dest.id = src.id
WHEN MATCHED THEN UPDATE
SET 
	dest.ColumnName1 = src.ColumnName1, --Replace with the columns you want to update. eg: dest.Param4 = src.Param4
	dest.ColumnName2 = src.ColumnName2; --Replace with the more columns you want to update. eg: dest.Param4 = src.Param5


That being said, it's ghetto and not recommended. If you happen upon this guide before you fuck something up give RoyalBlade's method a shot instead and use that in the future to make and test changes.

A BETTER METHOD

Code:
EXEC SP_RENAME _RefSkill, _RefSkillReal; --Renames the RefSkill table to _RefSkillReal
SELECT * INTO _RefSkill FROM _RefSkillReal; --Recreates the _RefSkill table from the data in _RefSkillReal
Now you can make changes and test things without index and foreign key restraints, and if something doesn't work you can just run

Code:
DROP TABLE _RefSkill; --Drop the table
SELECT * INTO _RefSkill FROM _RefSkillReal; --Remake it fresh from the backup
To start over with a fresh _RefSkill table from your last working version
Once your change is confirmed working you can create a query for your changes and then restore the original table and run the query to change things legitimately.

Code:
DROP TABLE _RefSkill; --Pretty self explanatory
EXEC SP_RENAME _RefSkillReal, _RefSkill; --Renames the real _RefSkill table back as it should be


Thanks to RoyalBlade's original post:

QuantumRising is offline  
Old 10/10/2016, 20:36   #2
 
Royalblade*'s Avatar
 
elite*gold: 85
Join Date: Feb 2014
Posts: 1,055
Received Thanks: 1,643
I've lost at least 5 years of life expectancy just seeing this load.

You are asking for improvements? Gotta remove it!

..... RAGE END:

How about you simply..


EXEC SP_RENAME _RefSkill, _RefSkillReal
SELECT * INTO _RefSkill FROM _RefSkillReal

Now you can go ahead and test **** on the new index & keyless RefSkill. You can edit data much easier without worrying about ****. No Primary keys, no foreign keys, no mofo to tap your nuts. If **** works, you apply the same change (which should always be 'querified') on the REAL table. Then you drop the test table and rename the real table back. Done.

No errors. No Insanity.

Peace out
Royalblade* is offline  
Thanks
1 User
Old 10/11/2016, 04:25   #3
 
B1Q's Avatar
 
elite*gold: 350
Join Date: Aug 2015
Posts: 1,999
Received Thanks: 1,184
*reads query*
*goes blind*
B1Q is offline  
Old 10/11/2016, 19:32   #4
 
elite*gold: 0
Join Date: Feb 2009
Posts: 173
Received Thanks: 14
Quote:
Originally Posted by Royalblade* View Post
I've lost at least 5 years of life expectancy just seeing this load.

You are asking for improvements? Gotta remove it!

..... RAGE END:

How about you simply..


EXEC SP_RENAME _RefSkill, _RefSkillReal
SELECT * INTO _RefSkill FROM _RefSkillReal

Now you can go ahead and test shit on the new index & keyless RefSkill. You can edit data much easier without worrying about shit. No Primary keys, no foreign keys, no mofo to tap your nuts. If shit works, you apply the same change (which should always be 'querified') on the REAL table. Then you drop the test table and rename the real table back. Done.

No errors. No Insanity.

Peace out
I did say it would give you a heart attack didn't I?

Anyway this is a better method for sure. Updated.

Quote:
Originally Posted by hazemooking View Post
*reads query*
*goes blind*
We all do stupid things when we're learning
QuantumRising is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
The problem with restoring SQL 2008 database billing.bak
03/12/2013 - Dekaron Private Server - 4 Replies
Hello I have a problem with restoring database and accurate it is about is that I can not get used a restore billing.bak the instructions from that address and from what I know it should look like this: http://i.imgur.com/OTVWR.png au me in restoring the database looks like this: http://i.imgur.com/dM2h0yC.png?1
[GUIDE]Alternative way to restore database for MSSQL 2005
02/24/2013 - SRO PServer Guides & Releases - 6 Replies
Hello guys I just found way to restore database (2005) I was just getting this problem ERROR:http://i.imgur.com/dumld.png So i worked for some time and found the solution Solution: Create first the databases.
Table restore
08/16/2012 - SRO Private Server - 3 Replies
is there any option in sql 2008 r2 to restore a table only not a hole db ? because i have my RefObjCommon table got fucked up . so i want to delete it and copy new lines but i cant delete it . it gives an error . (cannot truncate table Refobjcommon because it is being referenced by a FOREIGN KEY constraint
How To Restore Table In SQL
07/15/2012 - SRO Private Server - 0 Replies
Thread Is Shown From Subject Now Any One Know Pls Tell Me:confused:
Cant restore database
01/28/2010 - Dekaron Private Server - 10 Replies
Hm who is using sql 2008? I cant seem to restore the billing database,account database restores succesfull but billing does not work. Any one stumped to this error to and how did you fix it? :mad:



All times are GMT +2. The time now is 07:01.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.