all groups > sql server replication > february 2006 >
You're in the

sql server replication

group:

Unique Constraints and Replication with Purging


Unique Constraints and Replication with Purging mrprice
2/6/2006 1:36:22 PM
sql server replication:
We’re using transactional replication to create two databases, one for
transactional data, and one for reporting data. In the transactional
database we will allow data purging via a stored proc. We will not replicate
the deletes caused by the purge stored proc to the reporting database. This
has already been tested and it works fine. However, we do have an issue with
various unique constraints in the reporting database causing replication to
fail because duplicate data is allowed in the transactional database because
of purging.

Is it standard practice to just remove all the unique constraints from the
reporting database after the snapshot has been completed? Is there a way to
not bring unique constraints over in the snapshot to begin with?

Thanks,
Mark
Re: Unique Constraints and Replication with Purging Paul Ibison
2/6/2006 10:41:21 PM
Mark,
have a look at the @schema_option argument in sp_addarticle. It finely
controls what is taken across in the snapshot and there is a value for
unique keys.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

Re: Unique Constraints and Replication with Purging Hilary Cotter
2/7/2006 5:39:47 AM
Either modify your insert logic to do an existence check before doing the
insert, or use the continue on data consistency error. Note that you have to
be a little careful here otherwise your reporting database will get quite
out of sync. Basically the same insert or an insert with the same key value
is coming across twice. If it is the same row you are ok, if it has the same
key data, but different non key values, you have to ensure that this meets
your business case as you will be throwing away the new values.

--
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com

[quoted text, click to view]

Re: Unique Constraints and Replication with Purging mrprice
2/7/2006 10:19:27 AM
Paul,

I looked at this but I can't seem to figure out the correct value. Right
now the value being passed for tables is 0x00000000000000F3. Basically all I
want to replicate is the primary key for each table. I don't need DRI,
triggers, or other constraints replicated.

Thanks,
Re: Unique Constraints and Replication with Purging mrprice
2/7/2006 10:27:27 AM
Hilary,

Thanks for response. The unique contraints I mention here are not key
values. The are simply constraints, which become indexes at the sunscriber,
on non primary key fields. This is why I thought it would be better to
simply remove them via a post snapshot script.

Thanks,
Mark

P.S. I can't tell you how much of a help your SQL 2000 replication book has
been to me. Thanks!

[quoted text, click to view]
Re: Unique Constraints and Replication with Purging Paul Ibison
2/8/2006 12:00:00 AM
Mark,

this should be what you need:

@schema_option = 0x8083

The options I'm including are:

0x01
Generates the object creation (CREATE TABLE, CREATE PROCEDURE, and so
on). This value is the default for stored procedure articles.

0x02
Generates custom stored procedures for the article, if defined.

0x80
Includes declared referential integrity on the primary keys.

0x8000
Replicates primary key and unique keys on a table article as
constraints using ALTER TABLE statements.



Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

Re: Unique Constraints and Replication with Purging mrprice
2/14/2006 11:46:21 AM
Paul,

I think I should better explain. I have a table with three fields.

alertTypeID int IDENTITY (1, 1) NOT NULL
name nvarchar(50) NOT NULL
warningFl bit NOT NULL

The second field "name" has a UNIQUE constraint, CONSTRAINT
[AKalertType_name] UNIQUE NONCLUSTERED.

As we are doing data purging on the source database, there is always the
remote possibility that an entry in the "name" field could be duplicated. If
I allow the UNIQUE index to be created at the subscriber, replication will
stop if this scenario occurs.

How might I either 1) prevent the UNIQUE index from being creating during
the snapshot, 2) remove the UNIQUE index after the snapshot has completed, or
3) prevent replication from stopping when it encounters such and error?

Thanks,
Re: Unique Constraints and Replication with Purging Paul Ibison
2/15/2006 12:00:00 AM
(1) To prevent the unique constraint, have a look at sp_addarticle
(@schema_option) as in my previous post.
(2) to remove the constraint after the table has been created you can use a
post-snapshot script, or sp_addscriptexec
(3) The SKIPERRORS parameter (provided you know the error number) will allow
replication to continue after such errors.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

Re: Unique Constraints and Replication with Purging mrprice
2/16/2006 5:38:32 AM
Paul,

Thanks! #1 worked perfectly.

Mark

[quoted text, click to view]
AddThis Social Bookmark Button