Copy stored procedure's from one database to other - database

I am trying to copy a database with huge data from SQL Server 2005 to SQL Server 2008. I tried using the Copy Database Wizard but could not use the wizard because they are two different server 2005 and 2008. So I copied all the tables using Import data wizard from SQL Server 2008.
I had about 1120 stored procedures to be copied, so on SQL Server 2005 I used the Generate Script wizard and created script(for SP) which I could run on SQL Server 2008. I ran that script on SQL Server 2008, but only 1082 procedures were created, most of them didn't get created because of dependency issues. Now I am not sure out of 1120 SP's which were not created.
Can you suggest anything on how to fix this situation?

SQL Server 2008 can restore from a SQL Server 2005 backup file. Why don't you just do a quick backup and restore operation? If you don't want the whole thing, just backup and restore to a temporary SQL 2008 database and then copy the objects you need from there.

In order to find out which stored procedures are missing and need to be re-created, you should use a SQL diff tools, something like:
Red-Gate SQL Compare
ApexSQL SQL Diff
Those do cost a bit of money to license, but they're well worth their purchase price and can save you countless hours of work trying to figure out what needs to be done.
Both those tools can compare two databases (even different versions) against one another, and they can create either update scripts to make them have the same objects, or you can even do the synchronisation directly in those tools, if you wish to do so.

What kind of dependency issues?
Most of the time it will just complain about dependency issues, for example if you try to execute a SP from a SP that is not yet created. But it will still be created.
It might be logins or such?
Why dont you just make a backup and restore the database?

Would it not be simpler to just Detach the SQL 2005 DB, copy the .mdf and .ldf files for the DB to the SQL 2008 Data folder, and then Attach the DB?

Related

How to make SQL Server 2008 compatible to SQL Server 2000

I have to run the backup of SQL Server 2000 in SQL Server 2008.
While restoring the database from the .bak file, I got the error
specified cast is invalid
After doing google I feel there is compatibility issue. Therefore I want to make the database compatibile to SQL Server 2000.
And run the below query
ALTER DATABASE DBNAME
SET COMPATIBILITY_LEVEL = 80
but nothing help. Any help will be appreciated.
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server (like 2008) down to an older version (like 2000) - the internal file structures are just too different to support backwards compatibility.
You can either get around this problem by
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
Changing the compatibility level will get you closer to SQL 2000 but there were breaking changes (more likely they came in when 2005 did), unfortunately you will need to find where you get things that break and manually fix them.
Ed

Is it possible to restore data from a table in sql server 2005 to sql server 2008?

A client has no option but to migrate from sql server 2000 to 2008 within the next few days. Tests have shown unacceptable performance degradation in vital functionality in 2005 but not in 2008. Good stuff however, the application uses DTS to import external market data into the database and DTS is no longer supported by 2008.
Until such time as the function can be rewritten, I'm thinking the import could be done in an instance of 2005 and the data (from one table) subsequently uploaded into 2008.
(a) is there an alternative option?
(b) if not, is there a simple way of achieving the data upload from 2005 to 2008?
Any assistance/advice gratefully received.
I might be misunderstanding what you need to do, but one thing you can do to move a database from from 2005 to 2008 is to just back up the database on the 2005 instance to a .bak file: right-click on the database in the Object Explorer in Management Studio (or whatever it's called in your version of SQL Server!), and do Tasks -> Backup database, and save it somewhere you can see from both instances. Then go to the 2008 instance do "Tasks -> Restore database" in the 2008 instance and the restored copy of the database should just work in 2008.
I think you might have trouble going the other way though, with this method.
You could use an SSIS package to execute the DTS packge, and AFAIK you can execute DTS 32 bit in SQL 2008 (MS link). The other option would be to run the database in a compatibility mode which ~may~ avoid the performance issues you're seeing. All in all, you might be better off rewriting your DTS with SSIS. The concepts similar and you shouldn't have too much trouble recreating it with SSIS.

SQL Server 2005 and SQL Server 2008 how to make it compatible?

I have in production SQL Server 2005 and in Development SQL Server 2008 Database.
I would like to detach database from production create tables, insert data etc. and then attach it back.
How make it compatible after I make some changes in SQL server 2008?
What is the right way to do it?
There is no way to do this.
The only way I know to move a database from MSSQL2008 to 2005 is to script the tables.
Once the new tables are created in 2005, you can transfer the data either by scripting it (no fun) or by the data transfer wizard.
Changes to tables and data (for lookup tables) should be scripted and in source control like any other code. Then you run the scripts for the changes you are promoting to prod. This way other dev changes which are not ready to go to prod can be held back from being sent to prod.
I also do not recommend that you have a development database in a differnt version of SQL Server unless what you are testing to see if anything needs to be changed in preparation of moving to 2008. Otherwise, it is highly likely that bad code will be written that the prodcution database cannot handle becasue it is the wrong version and you will not find this out until you send the change to production.

Copying Data from SQL Server 2008 to SQL Express

I would like to copy a database (tables, it’s data, stored procs & views) from SQL Server 2008 database to SQL Server Express. Is it possible? If so, would you please let me know how to do it? When I tried, it is giving some error.
Please note that I have only few records in SQL Server 2008 database tables.
Thanks and Regards..
Shruthi Keerthi..
The quickest way is to "detach" the source database from its server, copy the (2) files to a new name/location and (re)attach each database to the appropriate server.
Attach/detach is available as a command or via the SQL Visual Studio.
You can create a backup of the database and them restore that backup into the Express instance.
Another option, since you said you didn't have very many records in the DB, is to generate the SQL statements (right click on the database --> tasks -> generate scripts) and then run that on the Express instance. Then just copy over the tuples you want.
I prefer to use Backup/Restore when moving a database from one server to another. As long as your SQL Server and SQL Express are the same version, or the one you are moving to is newer than the one you are moving from (SQL 2005 to SQL Express 2008), it should work without a hitch.
If copying the entire database, I usually find it easiest to stop the source service, copy the *.mdf file to the appropriate new data directory, and just mount the MDF in the new service. As long as there aren't any changes in the setup (like FILESHARE), then this is the easiest way to clone a database.
And yes, this is possible. I just did this earlier today.
You could also try using the Microsoft Database Publishing Wizard.
It's simple to use and will create a SQL script that you can run to rebuild tables (including data), stored procs, views, etc...
You can download it here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en

Can an MS SQL 2005 backup be restored onto an instance of MS SQL 2008?

Is it possible to restore a backup of a SQL Server 2005 database onto an instance of SQL Server 2008?
I need to rebuild a server as it's getting rather crufty, so I plan to take this opportunity to upgrade to SQL 2008 and wondered if I'll be able to restore my backups OK.
Upgrading from 2005 to 2008 is OK, moving back might require more work
N.B. You might have a problem with your database the logins (as they will not exist in the new server master db) but that's something which would happen regardless of the server version. Just re-create them and re-associate with your database.
Yes, but make sure that ALL of your servers are SQL 2008. If you have development, test, QA or disaster recovery servers, all of them will need to be 2008, since 2005 servers won't be able to restore a 2008 backup.
To prevent the lost-login problem that Ilya mentioned, follow the steps in this knowledge base article. SP_Help_Revlogin will script out your logins, and you can apply that script on the new server. Presto, all your logins are back with the same SIDs and everything.
http://support.microsoft.com/kb/246133
(And just for future reference, this is how we upgraded StackOverflow last night, heh.)
http://twitter.com/SuperDalgas/status/976719756
You can restore the 2005 backup with 2008 without any problems. The compatibility from this point of view is nice.
Backward is not possible only with backup files.
In any case you can also recreate the database structure and use SSIS to transfer data from one server to another.
You can also do a detach/attach with the database files (leastways you could going from 2000 to 2005), but there are more caveats with this approach (requires explicit rebuild indexes afterwards IRRC)

Resources