Database replication from SQLserver 2000 to SQLserver 2008 - sql-server

I'm trying to replicate a rather large database from SQLServer 2000 to SQLServer 2008, located on two different servers. I found an article about attempting this and have been trying to follow its direction. Here is the article.
Mixed Mode Bi-Directional Transactional Replication between SQL 2000 and SQL 2008
Here is the part I'm stuck on:
"So, to create a publication, you will
need to NOT use the publication wizard
that you get in SQL 2008. Instead, use
a generated publication script and for
each sp_addarticle line that you have
in it, make sure that the #ins_cmd,
#upd_cmd & #del_cmd parameters point
to the appropriate stored procedures
and run it on the SQL Server 2000
server. Once this is done, go ahead
and create a subscription to SQL
Server 2008’s database normally."
I was able to get the stored procedures in place for all of the tables but need some direction on creating a generated publication script. Does anyone have some direction or a good example of a generated publication script?

On the final step of the publication wizard you will have the two options:
1. Create the publication
2. Generate a script file with steps to create the publication
The article referenced here is suggesting that you do not let the wizard create the publication but instead only choose to generate the script file. At that point you can edit the script file as instructed in the article.

You can run through the SQL Publication Wizard in 2008 and have it output to a script and then use that as a base model to modify with the appropriate arguments for the sp parameters listed in the question.

I'm just doing an upgrade of SQL 2000 to SQL 2008 R2 and I'm finding the publication wizard works just fine without any need to modify the scripts generated.
The article suggests creating some stored procs because it does not work bi-directionally out of the box. However, when it works brilliantly both directions, and very quickly too, just using the wizard. This is using SQL 2008 R2 which may be the reason, it may have improved since the original SQL 2008.

Related

Backup a single table in SQL server not using Select into

For SQL Server 2008 is there an out of the box way to backup a singe table? On other database I've seen straightforward backup and restore commands for a single table but have not found it on SQL Server.
I am looking for commands like backup table and restore table which I've come across for other databases.
Use powershell to copy the table from one server/database to another.
http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/06/use-powershell-to-copy-a-table-between-two-sql-server-instances.aspx
This uses the sql client library and bulk copy. As long as you have credentials, this can be executed anywhere as long as powershell is installed!
There is one option using SSMS.
Check this out.

Sql Server Scripting Data Only: Workaround for CyclicalForeignKeyException?

I have a SQL Server DB that I want to script data for from a single table. When I try this I get the CyclicalForeignKeyException- presumably because somewhere there is an FK cycle, which is fine. This seems to be an annoying limitation of SQL Server, and in my case, I'm using SQL Server 2008 R2.
The 3 suggestions I've read for this are:
Get rid of the cycles. (Not an option as I don't want to modify this DB.)
Temporarily remove the keys and reset them afterwards. (Not an option for the same reason.)
Script all objects in the DB. (This would be possible, but this DB is large so this it not an ideal solution.)
Another similar suggestion I read was to backup the DB and restore a temp copy, remove the FKs, then get the data. But again since the DB is large, this isn't ideal either.
Any one have another idea?
Wow- I can't believe this worked...
I have a similar version of the DB I was trying to get data for on another machine. This time when I ran the tool it worked. (By tool I mean: Tasks->Generate Scripts... select 1 table, in advanced, change "Types of data to script" to "Data only".)
At first I thought this other version of the DB must not have the cyclical keys, but then I realized that I was using SQL Server Management Studio 2012 Express. So then I closed SSMS, did a runas /netonly with the domain user and opened SSMS 2012 and connected to the SQL Server 2008 R2 DB. I retried to generate the script and it worked!
Apparently SSMS 2012 fixed this "issue" and you can even use it against other DB versions!

How can I generate a script of my database as it is?

My primary reason for this is to keep track of database schema changes for my application. In SQL Server Management Studio I am able to generate a create script which creates the database but it doesn't contain any test data. Ideally when the script is run it should DROP the existing database (assuming it already exists) and then recreating it using this new script containing schema changes and test data from my development machine.
So how can I generate a script that will create a database with all the tables, stored procs, triggers, views, test data, etc?
I've tried using the import/export functionality but that's no good because it doesn't seem to copy over stored procedures. Plus it would be nice to have a script so I can track changes to the schema using mercurial.
I am using SQL Server Express 2008 R2 along with SQL Server Management Studio.
You didn't mention which version of SQL Server, but in SQL 2008 this is very easy
SQL 2008
Expand Databases
Right Click Database
Choose Tasks > Generate Scripts
Generate and
Publish Dialog will open Choose your
objects (i.e. Tables, procs, etc)
Click Next On the Set Scripting
Options choose Advanced Options Under
General choose SCRIPT DROP AND
CREATE - SCRIPT DROP AND CREATE
Types of Data To Script - Schema and
Data Close Advanced Window Choose to
save to file.
I wrote an open source command line utility named SchemaZen that does this. It's much faster than scripting from management studio and it's output is more version control friendly. It supports scripting both schema and data.
To generate scripts run:
schemazen.exe script --server localhost --database db --scriptDir c:\somedir
Then to recreate the database from scripts run:
schemazen.exe create --server localhost --database db --scriptDir c:\somedir
Try Microsoft SQL Server Database Publishing Wizard. This is a powerful flexible tool for scripting schema / data rom SQL Server.
Personally I use Microsoft Visual Studio 2010 Database Project with a Source Control Repository (SVN) to track changes to the schema.
Watch out for difference in database collation. If you develop on a database with a case insensitive collation and try and run the SSMS generated scripts against as database with a case sensitive collation then errors in case will break the scripts.
Usually i make backups fom a database before start a new development on it.
the best way is restore the backup when needed, i don't know how to get it by the script way!

How do you pull data from SQL Server to Oracle?

I'm wanting to take data from a SQL Server table and populate a Oracle table. Right now, my solution is to dump the data into a Excel table, write a macro to create a sql file that I can load into Oracle. The problem with this is I want to automate this process and I'm not sure I can automate this.
Is there an easy way to automate populating a Oracle table with data from a SQL Server table?
Thanks in advance
I suppose it depends on your definition of "easy".
The most robust approach would be to either use heterogeneous connectivity in Oracle to create a database link to the SQL Server database and then pull the data from SQL Server or to create a linked server in SQL Server that connects to Oracle and then push the data from SQL Server to Oracle.
Yes. Take a look at MS SQL's SSIS which stands for SQL Server Integration Services. SSIS allows all sorts of advanced capabilities, including automated with Sql Server Jobs, for moving data between disparate data sources. In your case, connecting to Oracle can be achieved a variety of ways.
There are three ways to automate this:
1) You can do as Paul suggested and created an SSIS package that will do this and it can be scheduled via SQL Agent,
2) If you don't want to deal with SSIS, you can download the free SQL# (SQLsharp) CLR Library from http://www.SQLsharp.com/ and use the DB_BulkCopy Stored Procedure to do this in a T-SQL Stored Proc which can also be scheduled via SQL Agent. [note: I am the author of SQL#]
3) You can also set up a Linked Server from SQL Server to Oracle, but this has the draw-back of being a potential security hole. Of course, you could use an Oracle Login that only has write-access to that single table (or something similar to that).
There are lots and lots of ways to do it. Which you choose depends on your requirements.
Using Excel is fine if it's a one time thing.
If it's a once-in-a-while thing, then you could write a simple .NET app that uses a single DataSet and multiple DataAdapters to do the data dump. C# code example here.
if it's a regular thing, then you could put the above in a Schtasks task, or you could use SSIS. I think SSIS is an extra-cost option.
if the requirement is for "online access", then a linked database is probably appropriate.

How can I copy data records between two instances of an SQLServer database

I need to copy some records from our SQLServer 2005 test server to our live server. It's a flat lookup table, so no foreign keys or other referential integrity to worry about.
I could key-in the records again on the live server, but this is tiresome. I could export the test server records and table data in its entirety into an SQL script and run that, but I don't want to overwrite the records present on the live system, only add to them.
How can I select just the records I want and get them transferred or otherwise into the live server? We don't have Sharepoint, which I understand would allow me to copy them directly between the two instances.
If your production SQL server and test SQL server can talk, you could just do in with a SQL insert statement.
first run the following on your test server:
Execute sp_addlinkedserver PRODUCTION_SERVER_NAME
Then just create the insert statement:
INSERT INTO [PRODUCTION_SERVER_NAME].DATABASE_NAME.dbo.TABLE_NAME (Names_of_Columns_to_be_inserted)
SELECT Names_of_Columns_to_be_inserted
FROM TABLE_NAME
I use SQL Server Management Studio and do an Export Task by right-clicking the database and going to Task>Export. I think it works across servers as well as databases but I'm not sure.
An SSIS package would be best suited to do the transfer, it would take literally seconds to setup!
I would just script to sql and run on the other server for quick and dirty transferring. If this is something that you will be doing often and you need to set up a mechanism, SQL Server Integration Services (SSIS) which is similar to the older Data Transformation Services (DTS) are designed for this sort of thing. You develop the solution in a mini-Visual Studio environment and can build very complex solutions for moving and transforming data.

Resources