Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Thursday, March 29, 2012

Alternate Synchronization Partner Error

Greetings:
I am working on a setting up an alternate synchronization partner, and
getting an error. Bear with me as the explanation of what I have done so far
is long.
We have about 75 customers with about 100 pull subscriptions using about 20
publications in merge replication with Sql Server 2000. Our customers are
located where many have dial up connections and they need to set own
synchronization schedules. All are synchronizing with programs we wrote in
VB 6.0 using SQLDMO and the ActiveX merge control. All our customers have
been able to successfully synchronize now for many months, so we know our
programs are working as they should. They all synchronize over the internet
to a single publisher/distributor.
We would like to build some redundancy into our topology so that we have an
alternate synchronization server, or partner, as the BOL calls it, in case
the primary publisher fails. However, we want to locate the alternate synch
partner at a site other than where the primary publisher is located.
I have printed the MS KB article # 321176 on how to set up an alternate
synch partner. I also listened to the web cast from MS on this subject.
Following the KB #321176, I have set up two test databases, and a
subscriber. There is publisher A, and publisher B, with subscriber A.
Publisher A is the primary publisher and publisher B is to become our
alternate synch server. As the KB article and web cast said to do, I have
completed the following:
1.Created a global pull subscription on publisher B to publisher A.
2.Created a publication on publisher B which is identical to the database
on publisher A. The database names on both publisher A and publisher B are
the same name as are the publication names.
3.Generated a snapshot of the database on publisher B.
4.Enabled subscriber A on publisher B.
5.Set the alternate synch partners on both publisher A and publisher B so
each can use the other as a synch partner.
6.Created a pull subscription to publisher A from subscriber A which
synchronizes fine.
I then have tried to synchronize to the alternate publisher B from
subscriber A by changing the job commands as described in the KB article, but
get an error. In fact, the merge agent is able to connect to publisher B,
and initializes the process. In other words, I believe I have everything
set up correctly since the subscriber A connects and initializes to publisher
B. When it starts the actual synchronization, I get the following message:
“The process could not drop one or more tables because the tables are being
used by other publications.“ This is shown as error # -2147200976.
Apparently, subscriber A is trying to use the snapshot from publisher B,
which has scripts that tell it to drop tables. However, the tables trying to
be dropped are the subscription database as it was originally set up from the
pull subscription to publisher A. So, while the error make sense in a way
because the tables are replicated, subscriber A cannot synchronize to
publisher B because it is stopped by the error.
What am I doing wrong?
Do the database names and/or the publication names on the two publishers
need to be different? I had read one reference in BOL that said they should
be the same, but the KB article seems to imply otherwise.
I have found very little on any internet web site about Sql Server that
describes setting up and running alternate synch partners. Microsoft has the
most I have found on the subject, and I think I am following the MS set-up
correctly.
Any help would be gratefully appreciated.
Thanks!
Bill
Hi Bill,
From your descriptions, I understood that when applying alternate
synchronization partner, you encouter the error message "The process could
not drop one or more tables because the tables are being used by other
publications." Have I understood you? Correct me if I was wrong.
Based on my knowledge, this is because some entries does not match between
table sysmergepublications and sysmergesubscriptions on the publisher and
subscriber. A quick resolution is drop the publication completely and then
create it again.
How to manually remove a replication in SQL Server 2000
http://support.microsoft.com/kb/324401
I understood drop the publication may have huge business impact to your
business, as an option, please send the the result of following T-SQL
statement. I would like to check to see whether I could help further
select * from sysmerge_subscriptions
go
sp_helpserver
However, please understand that this replication issues tend to be very
complex and hard to troubleshoot in newsgroups. If you need further
assistance, I recommend that you open a Support incident with Microsoft
Customer Service and Support (CSS) so that a dedicated Support Professional
can work with you in a more timely and efficient manner. If you need any
help in this regard, please let me know.
For a complete list of Microsoft Customer Service and Support phone
numbers, please go to the following address on the World Wide Web:
<http://support.microsoft.com/directory/overview.asp>
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/tec...rview/40010469
Others: https://partner.microsoft.com/US/tec...pportoverview/
If you are outside the United States, please visit our International
Support page: http://support.microsoft.com/common/international.aspx
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Hi Michael:
On a hunch before I sent you the requested the information, I changed the
database name on the alternate synch server (Publisher B) to a name that was
different from the original on Publisher A. Then the subscriber A was able
to sychronize with Publisher B, so I made it over that hurdle.
However, now, Subscriber A will not syncrhonize with Publisher A, but only
with Publsiher B. I get the following error:
"The Publisher has been restored from a backup whose schema change version
is different from the Subscriber. Rerun the Snapshot Agent and reinitialize"
The Publisher has NOT been restored from a backup. However, I went ahead as
the message said and reran the snapshot and reinitialized the subscription
from Subscriber A. Now the subscriber will not synch with Publisher B, and I
get the same error as above. So, on Publisher B, I do the snapshap again,
and reinitialize the subscription and then synch and it works. Then I try to
synch to Publisher A again, and get the error.
In other words, after I get a successful synch to either of the publishers,
I get the error on the other one the next time I try to synch to the other.
It is like an infinite loop. One works, the other doesn't. I run the
snapshot on the other and reinitialize, and it synchs, and then first one
doesn't, etc, etc. etc.
What is wrong now?
Thanks in advance for any help you can give!
Bill
"Michael Cheng [MSFT]" wrote:

> Hi Bill,
> From your descriptions, I understood that when applying alternate
> synchronization partner, you encouter the error message "The process could
> not drop one or more tables because the tables are being used by other
> publications." Have I understood you? Correct me if I was wrong.
> Based on my knowledge, this is because some entries does not match between
> table sysmergepublications and sysmergesubscriptions on the publisher and
> subscriber. A quick resolution is drop the publication completely and then
> create it again.
> How to manually remove a replication in SQL Server 2000
> http://support.microsoft.com/kb/324401
> I understood drop the publication may have huge business impact to your
> business, as an option, please send the the result of following T-SQL
> statement. I would like to check to see whether I could help further
> --
> select * from sysmerge_subscriptions
> go
> sp_helpserver
> --
> However, please understand that this replication issues tend to be very
> complex and hard to troubleshoot in newsgroups. If you need further
> assistance, I recommend that you open a Support incident with Microsoft
> Customer Service and Support (CSS) so that a dedicated Support Professional
> can work with you in a more timely and efficient manner. If you need any
> help in this regard, please let me know.
> For a complete list of Microsoft Customer Service and Support phone
> numbers, please go to the following address on the World Wide Web:
> <http://support.microsoft.com/directory/overview.asp>
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
> Business-Critical Phone Support (BCPS) provides you with technical phone
> support at no charge during critical LAN outages or "business down"
> situations. This benefit is available 24 hours a day, 7 days a week to all
> Microsoft technology partners in the United States and Canada.
> This and other support options are available here:
> BCPS:
> https://partner.microsoft.com/US/tec...rview/40010469
> Others: https://partner.microsoft.com/US/tec...pportoverview/
> If you are outside the United States, please visit our International
> Support page: http://support.microsoft.com/common/international.aspx
> ================================================== ===
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
|||Hi,
I found you may encounter the problem described by KB article 814460
FIX: Merge Replication with Alternate Synchronization Partners May Not
Succeed After You Change the Retention Period
http://support.microsoft.com/kb/814460
Please feel free to ask this hotfix by contacting CSS. If you are simply
requesting a hotfix be sent to you and no other support then charges are
usually refunded or waived.
To obtain the phone numbers for specific technology request please take a
look at the web site listed below.
http://support.microsoft.com/default...S;PHONENUMBERS
NOTE that the hotfix is only intended to correct the problem that is
described in this article. Only apply it to systems that are experiencing
this specific problem. This hotfix may receive additional testing.
Thank you for your patience and corporation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/tec...rview/40010469
Others: https://partner.microsoft.com/US/tec...pportoverview/
If you are outside the United States, please visit our International
Support page: http://support.microsoft.com/common/international.aspx
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Thank you, Michael. This sounds like the issue I am having.
I looked at the "http://support.microsoft.com/kb/814460" as you suggested.
At the bottom of the page is says that the fix is also included in "MS03-031:
Security patch for SQL Server 2000 Service Pack 3" and gives a link to
download it, so I would prefer to do that rather than place a phone call as I
think it will save time.
However, in the middle of the KB # 814460, it says:
"The problem exists in SQL Server 2000 Service Pack 3, version 8.00.0760. To
fix this version, you must apply SQL Server 2000 Service Pack 3 rollup,
version 8.00.0765."
The versions we are running are 8.00.0760 on both of the affected servers,
so I tried to find the "SQL Server 2000 Service Pack 3 rollup, version
8.00.0765" on the Microsoft web site and cannot. When I search both
downloads and the entire site, I get no hits except back to the KB # 814460.
Can you tell me where I can get "SQL Server 2000 Service Pack 3 rollup,
version 8.00.0765"?
Thank you.
Bill
"Michael Cheng [MSFT]" wrote:

> Hi,
> I found you may encounter the problem described by KB article 814460
> FIX: Merge Replication with Alternate Synchronization Partners May Not
> Succeed After You Change the Retention Period
> http://support.microsoft.com/kb/814460
> Please feel free to ask this hotfix by contacting CSS. If you are simply
> requesting a hotfix be sent to you and no other support then charges are
> usually refunded or waived.
> To obtain the phone numbers for specific technology request please take a
> look at the web site listed below.
> http://support.microsoft.com/default...S;PHONENUMBERS
> NOTE that the hotfix is only intended to correct the problem that is
> described in this article. Only apply it to systems that are experiencing
> this specific problem. This hotfix may receive additional testing.
> Thank you for your patience and corporation. If you have any questions or
> concerns, don't hesitate to let me know. We are always here to be of
> assistance!
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
> Business-Critical Phone Support (BCPS) provides you with technical phone
> support at no charge during critical LAN outages or "business down"
> situations. This benefit is available 24 hours a day, 7 days a week to all
> Microsoft technology partners in the United States and Canada.
> This and other support options are available here:
> BCPS:
> https://partner.microsoft.com/US/tec...rview/40010469
> Others: https://partner.microsoft.com/US/tec...pportoverview/
> If you are outside the United States, please visit our International
> Support page: http://support.microsoft.com/common/international.aspx
> ================================================== ===
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
|||Hi Bill,
Sorry that I should have clarified it more clearly.
Yes, You could download the patch available in the KB article 821277
MS03-031: Security patch for SQL Server 2000 Service Pack 3
http://support.microsoft.com/kb/821277
Let me know whether this security patch resolves your issue.
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Hi Michael:
Thanks for this reference. I have installed the hot fix on the alternate
synchronization server, but have not yet installed it on the primary server.
That will have to wait a couple of days as that server is very busy right now
with our customer's activity, so I won't be able to check the results on the
error I was getting for at least a couple of days. The hot fix requires Sql
Server to be stopped to install it, and we need to wait until a more
opportune time that has minimal impact on our customers.
I will be sure, however, to let you know the results when I have a chance to
test it. I just wanted you to know I won't be able to do my next testing on
this issue for a little while yet.
Thanks for your continuing help and I'll be sure to let you know what happens.
Bill
"Michael Cheng [MSFT]" wrote:

> Hi Bill,
> Sorry that I should have clarified it more clearly.
> Yes, You could download the patch available in the KB article 821277
> MS03-031: Security patch for SQL Server 2000 Service Pack 3
> http://support.microsoft.com/kb/821277
> Let me know whether this security patch resolves your issue.
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
|||Hi Bill,
I haven't heard back from you yet and I'm just writing in to see if you
have had an opportunity to perform the hotfix. If you could get back to me
at your earliest convenience, we will be able to go ahead
If you have any questions or concerns, don't hesitate to let me know. We
are always here to be of assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Hi Michael:
Sorry it took me so long to respond back to you. I have been extremely busy
with customer issues and a family crisis of sorts, so I didn't get time unitl
yesterday to do some more testing.
I applied the hotfix to the three servers involved and it eliminated the
error! I was able to synchronize successfully numerous times between all the
machines. I was very pleased with the result.
However, I had my business partner add a another subscriber late yesterday
afternoon. He was able to create a suscription fine to the primary synch
server, but when trying the alternate, he started getting some errors. But
we both had other matters to attend to at that time and did not have a chance
yet to analyze the errors and if it was the way Sql Server is setup on his
machine or some other issue. We will work on that issue today, and may have
some additional questions for you. We did apply the hotfix to the computer
he is using for this test.
Thanks for you continuing help.
Bill
"Michael Cheng [MSFT]" wrote:

> Hi Bill,
> I haven't heard back from you yet and I'm just writing in to see if you
> have had an opportunity to perform the hotfix. If you could get back to me
> at your earliest convenience, we will be able to go ahead
> If you have any questions or concerns, don't hesitate to let me know. We
> are always here to be of assistance!
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
|||Michael:
We resolved all the initial errors and have the test alternate synch partner
running well with two subscribers. We have been able to run many, many
successful test syncrhonizations to both servers now without difficulty.
Part of testing plan, however, is to make some schema changes, and I have
run into another problem there. I will start a new thread for this issue.
Thanks for your help.
Bill
"Michael Cheng [MSFT]" wrote:

> Hi Bill,
> I haven't heard back from you yet and I'm just writing in to see if you
> have had an opportunity to perform the hotfix. If you could get back to me
> at your earliest convenience, we will be able to go ahead
> If you have any questions or concerns, don't hesitate to let me know. We
> are always here to be of assistance!
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
> This posting is provided "AS IS" with no warranties, and confers no rights.
>

Alternate Rows in Matrix

Hi All,
I need the alternate bg colors of the rows in the matrix to be
white smoke and grey.
when i used the following expression it throws a error.
=iif(RowNumber(Nothing) Mod 2,"WhiteSmoke", "LightGrey")
The background color expression for the textbox â'ProfCountâ' has a scope
parameter that is not valid for RunningValue, RowNumber or Previous. The
scope parameter must be set to a string constant that is equal to the name of
a containing group within the matrix â'matrix1â'.
What i need to do get the alternate coloring in matrix,
Thanks in advance....I beleive I have posted an example called Matrix.Greenbar on
www.msbicentral.com
Look under Downloads, reporting services, RDL... There are several Matrix
examples there which will probably help you get started.
Hope this helps.
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Chandra" <Chandra@.discussions.microsoft.com> wrote in message
news:B95FDE7C-7DAA-4327-AA61-4C1045DDEABA@.microsoft.com...
> Hi All,
> I need the alternate bg colors of the rows in the matrix to be
> white smoke and grey.
> when i used the following expression it throws a error.
> =iif(RowNumber(Nothing) Mod 2,"WhiteSmoke", "LightGrey")
> The background color expression for the textbox 'ProfCount' has a scope
> parameter that is not valid for RunningValue, RowNumber or Previous. The
> scope parameter must be set to a string constant that is equal to the name
of
> a containing group within the matrix 'matrix1'.
> What i need to do get the alternate coloring in matrix,
> Thanks in advance....sql

Tuesday, March 27, 2012

Altering XML Schema Collection Problem

Hi,
I'm trying to add an extra element into a schema collection and keep getting
an error message:
"Msg 9455, Level 16, State 1, Line 1
XML parsing: line 3, character 1, illegal qualified name character
"
The SQL I'm using is:
alter xml schema collection dbo.EmployeeSchemaCollection ADD N'
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
<xsd:element name="Employee">
<xsd:complexType>
<xsd:element name="HireDate" type="xsd:datetime" />
</xsd:complexType>
</xsd:element>
</xsd:schema>'
Can anyone help?
ThanksI don't know this stuff much however should not be a ">" in the end of the
second line? (<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema")
--
Ekrem Ã?nsoy
"John S" <js162@.newsgroup.nospam> wrote in message
news:F7FE9209-3176-4742-97AD-9689A20085A1@.microsoft.com...
> Hi,
> I'm trying to add an extra element into a schema collection and keep
> getting
> an error message:
> "Msg 9455, Level 16, State 1, Line 1
> XML parsing: line 3, character 1, illegal qualified name character
> "
> The SQL I'm using is:
> alter xml schema collection dbo.EmployeeSchemaCollection ADD N'
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> <xsd:element name="Employee">
> <xsd:complexType>
> <xsd:element name="HireDate" type="xsd:datetime" />
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>'
> Can anyone help?
> Thanks|||It's so easy to miss the obvious!
Thanks
JS
"Ekrem Ã?nsoy" wrote:
> I don't know this stuff much however should not be a ">" in the end of the
> second line? (<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema")
> --
> Ekrem Ã?nsoy
>
> "John S" <js162@.newsgroup.nospam> wrote in message
> news:F7FE9209-3176-4742-97AD-9689A20085A1@.microsoft.com...
> > Hi,
> >
> > I'm trying to add an extra element into a schema collection and keep
> > getting
> > an error message:
> > "Msg 9455, Level 16, State 1, Line 1
> > XML parsing: line 3, character 1, illegal qualified name character
> > "
> >
> > The SQL I'm using is:
> >
> > alter xml schema collection dbo.EmployeeSchemaCollection ADD N'
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > <xsd:element name="Employee">
> > <xsd:complexType>
> > <xsd:element name="HireDate" type="xsd:datetime" />
> > </xsd:complexType>
> > </xsd:element>
> > </xsd:schema>'
> >
> > Can anyone help?
> >
> > Thanks
>sql

Sunday, March 25, 2012

Alter View Hangs - Merge Replication SQL 2005

Background - I have a publication that propigates schema changes. I have a view in which I want to remove a column.

Error - Going by what the BOL says, I use Alter View and delete the column from my select statement. I issue the alter view command against the Publication database and it just "churns". I do not get any locking errors or any other type of error, but the statement never completes execution. I watched it run for 10 minutes and cancelled the query. Executing the same statement against a copy of the database that is not being published executes in 1, 2 seconds.

Here is what I am doing:

Old View: Select table1.record_number, table1.record_date, table1.status_code, table2.status_desc,

table2.txt_sort_order

FROM table1 join table2 on table1.status_code = table2.status_code

The query I am executing:

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER VIEW myview

AS

Select table1.record_number, table1.record_date, table1.status_code, table2.status_desc

FROM table1 join table2 on table1.status_code = table2.status_code

If this view is the only article in the publication, then it is a known issue.

Add a dummy table to the publication and your alter should succeed.

Thursday, March 22, 2012

ALTER TABLE statement error while rebuilding schema

I am running a product that is rebuilding several tables. On one table, after re-creating a table (afm_groups) with a new primary key constraint, I run the following line:
ALTER TABLE afm_flds ADD CONSTRAINT afm_flds_edit_group
FOREIGN KEY (edit_group) REFERENCES afm_groups(group_name)
go
And get the error:
ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'afm_flds_edit_group'.
The conflict occurred in database 'Hq', table 'afm_groups', column 'group_name'
There is no foreign key constraint built like this with this statement is executed. Any ideas?
This means that you have data in the edit_group column that doesn't have a
match in the afm_groups table.
(A foreign key's value must exist in the parent table.)
To identify the rows that are violating the foreign key:
SELECT * FROM afm_flds WHERE edit_group NOT IN (SELECT group_name FROM
afm_groups)
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"psrd66" <paul_doucette@.archibus.com> wrote in message
news:3B6C2338-2672-4D74-936B-17E3D728BEE4@.microsoft.com...
> I am running a product that is rebuilding several tables. On one table,
after re-creating a table (afm_groups) with a new primary key constraint, I
run the following line:
> ALTER TABLE afm_flds ADD CONSTRAINT afm_flds_edit_group
> FOREIGN KEY (edit_group) REFERENCES afm_groups(group_name)
> go
> And get the error:
> ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint
'afm_flds_edit_group'.
> The conflict occurred in database 'Hq', table 'afm_groups', column
'group_name'
> There is no foreign key constraint built like this with this statement is
executed. Any ideas?
>
|||Thanks, Aaron.
You were right. I created an invalid data condition somehow.
Paul Doucette
ARCHIBUS, Inc.

ALTER TABLE statement error while rebuilding schema

I am running a product that is rebuilding several tables. On one table, aft
er re-creating a table (afm_groups) with a new primary key constraint, I run
the following line:
ALTER TABLE afm_flds ADD CONSTRAINT afm_flds_edit_group
FOREIGN KEY (edit_group) REFERENCES afm_groups(group_name)
go
And get the error:
ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'afm_fld
s_edit_group'.
The conflict occurred in database 'Hq', table 'afm_groups', column 'group_na
me'
There is no foreign key constraint built like this with this statement is ex
ecuted. Any ideas?This means that you have data in the edit_group column that doesn't have a
match in the afm_groups table.
(A foreign key's value must exist in the parent table.)
To identify the rows that are violating the foreign key:
SELECT * FROM afm_flds WHERE edit_group NOT IN (SELECT group_name FROM
afm_groups)
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"psrd66" <paul_doucette@.archibus.com> wrote in message
news:3B6C2338-2672-4D74-936B-17E3D728BEE4@.microsoft.com...
> I am running a product that is rebuilding several tables. On one table,
after re-creating a table (afm_groups) with a new primary key constraint, I
run the following line:
> ALTER TABLE afm_flds ADD CONSTRAINT afm_flds_edit_group
> FOREIGN KEY (edit_group) REFERENCES afm_groups(group_name)
> go
> And get the error:
> ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint
'afm_flds_edit_group'.
> The conflict occurred in database 'Hq', table 'afm_groups', column
'group_name'
> There is no foreign key constraint built like this with this statement is
executed. Any ideas?
>|||Thanks, Aaron.
You were right. I created an invalid data condition somehow.
Paul Doucette
ARCHIBUS, Inc.sql

ALTER TABLE statement error while rebuilding schema

I am running a product that is rebuilding several tables. On one table, after re-creating a table (afm_groups) with a new primary key constraint, I run the following line
ALTER TABLE afm_flds ADD CONSTRAINT afm_flds_edit_group
FOREIGN KEY (edit_group) REFERENCES afm_groups(group_name
g
And get the error
ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'afm_flds_edit_group'.
The conflict occurred in database 'Hq', table 'afm_groups', column 'group_name
There is no foreign key constraint built like this with this statement is executed. Any ideasThis means that you have data in the edit_group column that doesn't have a
match in the afm_groups table.
(A foreign key's value must exist in the parent table.)
To identify the rows that are violating the foreign key:
SELECT * FROM afm_flds WHERE edit_group NOT IN (SELECT group_name FROM
afm_groups)
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"psrd66" <paul_doucette@.archibus.com> wrote in message
news:3B6C2338-2672-4D74-936B-17E3D728BEE4@.microsoft.com...
> I am running a product that is rebuilding several tables. On one table,
after re-creating a table (afm_groups) with a new primary key constraint, I
run the following line:
> ALTER TABLE afm_flds ADD CONSTRAINT afm_flds_edit_group
> FOREIGN KEY (edit_group) REFERENCES afm_groups(group_name)
> go
> And get the error:
> ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint
'afm_flds_edit_group'.
> The conflict occurred in database 'Hq', table 'afm_groups', column
'group_name'
> There is no foreign key constraint built like this with this statement is
executed. Any ideas?
>

ALTER TABLE statement conflicted with COLUMN FOREIGN KEY

I got the following Error
"ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
constraint 'FK_ABC_DEF'. The conflict occurred in
database 'Test', table 'DEF', column 'ID'."
when I ran the following scripts:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
GO
ALTER TABLE [dbo].[ABC] ADD
CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
(
[ID]
) REFERENCES [dbo].[DEF] (
[ID]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
My goal was to delete the constraint and recreate it but
the above error indicates that the FK constraint is still
active even when I verified on both tables and there were
not available.
Is this a problem with sqlserver 2000 or the problem is me.
Please help.Post your DDL for table dbo.DEF.
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:0ba901c48936$784343d0$3501280a@.phx.gbl...
I got the following Error
"ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
constraint 'FK_ABC_DEF'. The conflict occurred in
database 'Test', table 'DEF', column 'ID'."
when I ran the following scripts:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
GO
ALTER TABLE [dbo].[ABC] ADD
CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
(
[ID]
) REFERENCES [dbo].[DEF] (
[ID]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
My goal was to delete the constraint and recreate it but
the above error indicates that the FK constraint is still
active even when I verified on both tables and there were
not available.
Is this a problem with sqlserver 2000 or the problem is me.
Please help.|||Perhaps you have existing data that prevents the new constraint from being
created. You can identify this data with the query below:
SELECT *
FROM [dbo].[ABC] AS a
WHERE NOT EXISTS
(
SELECT *
FROM [dbo].[DEF] AS b
WHERE a.[ID] = b.[ID]
)
Hope this helps.
Dan Guzman
SQL Server MVP
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>|||Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
"Tom Moreau" wrote:

> Post your DDL for table dbo.DEF.
> --
> Tom
> ---
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>|||Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_AliasIDtb_RecipDemotb]') and OBJECTPROPERTY(id
,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[AliasIDtb] DROP CONSTRAINT FK_AliasIDtb_RecipDemo
tb
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_CMStb_RecipDemotb]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CMStb] DROP CONSTRAINT FK_CMStb_RecipDemotb
GO
CREATE TABLE [dbo].[RecipDemotb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL ,
[RecipSSN] [numeric](18, 0) NULL ,
[RecipLastNM] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NU
LL ,
[RecipFirstNM] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL ,
[RecipMiddleNM] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[RecipSuffix] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipPhone] [numeric](10, 0) NULL ,
[RecipDOB] [datetime] NULL ,
[RecipDOD] [datetime] NULL ,
[RecipAddress] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL ,
[RecipAddress2] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[RecipCounty] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipState] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipZip] [numeric](11, 0) NULL ,
[RecipRace] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MedIDNM] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EPSDTIND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipSex] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[TPLIND] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipNMCD] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipDOE] [datetime] NULL ,
[RecipIDNUM] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Buy_In_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Dup_Card_Code] [tinyint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[AliasIDtb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL ,
[MAID] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IdBeginDate] [datetime] NULL ,
[IdEndDate] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[CMStb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL ,
[CMS_PART_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[CMS_Beg_Date] [datetime] NULL ,
[CMS_End_Date] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RecipDemotb] WITH NOCHECK ADD
CONSTRAINT [PK_RecipDemotb] PRIMARY KEY CLUSTERED
(
[OriginalRecipid]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[AliasIDtb] ADD
CONSTRAINT [FK_AliasIDtb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[CMStb] ADD
CONSTRAINT [FK_CMStb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
"Tom Moreau" wrote:

> Post your DDL for table dbo.DEF.
> --
> Tom
> ---
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>|||Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_AliasIDtb_RecipDemotb]') and OBJECTPROPERTY(id
,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[AliasIDtb] DROP CONSTRAINT FK_AliasIDtb_RecipDemo
tb
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_CMStb_RecipDemotb]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CMStb] DROP CONSTRAINT FK_CMStb_RecipDemotb
GO
CREATE TABLE [dbo].[RecipDemotb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL ,
[RecipSSN] [numeric](18, 0) NULL ,
[RecipLastNM] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NU
LL ,
[RecipFirstNM] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL ,
[RecipMiddleNM] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[RecipSuffix] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipPhone] [numeric](10, 0) NULL ,
[RecipDOB] [datetime] NULL ,
[RecipDOD] [datetime] NULL ,
[RecipAddress] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL ,
[RecipAddress2] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[RecipCounty] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipState] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipZip] [numeric](11, 0) NULL ,
[RecipRace] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MedIDNM] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EPSDTIND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipSex] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[TPLIND] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipNMCD] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipDOE] [datetime] NULL ,
[RecipIDNUM] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Buy_In_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Dup_Card_Code] [tinyint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[AliasIDtb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL ,
[MAID] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IdBeginDate] [datetime] NULL ,
[IdEndDate] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[CMStb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL ,
[CMS_PART_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[CMS_Beg_Date] [datetime] NULL ,
[CMS_End_Date] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RecipDemotb] WITH NOCHECK ADD
CONSTRAINT [PK_RecipDemotb] PRIMARY KEY CLUSTERED
(
[OriginalRecipid]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[AliasIDtb] ADD
CONSTRAINT [FK_AliasIDtb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[CMStb] ADD
CONSTRAINT [FK_CMStb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
"Dan Guzman" wrote:

> Perhaps you have existing data that prevents the new constraint from being
> created. You can identify this data with the query below:
> SELECT *
> FROM [dbo].[ABC] AS a
> WHERE NOT EXISTS
> (
> SELECT *
> FROM [dbo].[DEF] AS b
> WHERE a.[ID] = b.[ID]
> )
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
>
>|||Actually, we really need the DDL for table dbo.DEF.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
.
"stoko" <stoko@.discussions.microsoft.com> wrote in message
news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
"Tom Moreau" wrote:

> Post your DDL for table dbo.DEF.
> --
> Tom
> ---
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>|||On Wed, 8 Sep 2004 12:15:05 -0700, stoko wrote:

>Below is the info you requested. Each time I drop the constraints via sql
>analyzer and try recreating them, I have the FK error. I check via EM and
>the constraints are not there. What must be going on is beyond my
>comprehension. Initially, the first 4 attempts works fine but there-after,
>nothing works. Remember that the tables have data.
>Let me know...
>Thanks in advance.
>Stoko.
(snip code)
Hi Stoko,
The code you supplied works fine for me. And when I append the code from
your original post, I get the following error:
Server: Msg 4902, Level 16, State 1, Line 3
Cannot alter table 'dbo.ABC' because this table does not exist in database
'TestDB80'.
Somehow, you seem to have posted the wrong tables here.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Tom,
It would have saved us some time if you renamed the tables to DEF. The DDL
I sent are production tables. I was trying to change the names, etc, but
decided to send you the live information. Thus far, no one has been able to
help explain why I cannot delete and recreate constraints in a sp or script
or dts on tables that have records. The irony is that this thing worked the
first few times and just fails thereafter -- requiring me to recreate the
constraints manually.
I am still waiting for your support.
Thanks.
Stoko.
"Tom Moreau" wrote:

> Actually, we really need the DDL for table dbo.DEF.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com
> ..
> "stoko" <stoko@.discussions.microsoft.com> wrote in message
> news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
> Below is the info you requested. Each time I drop the constraints via sql
> analyzer and try recreating them, I have the FK error. I check via EM and
> the constraints are not there. What must be going on is beyond my
> comprehension. Initially, the first 4 attempts works fine but there-after
,
> nothing works. Remember that the tables have data.
> Let me know...
> Thanks in advance.
> Stoko.
> "Tom Moreau" wrote:
>
>|||It will save you even more time if you simply provide the DDL for BOTH
tables. I cannot help you until you do that.
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"stoko" <stoko@.discussions.microsoft.com> wrote in message
news:F2F57F9B-D3E5-4B47-A53E-4A2F2750E2FB@.microsoft.com...
Tom,
It would have saved us some time if you renamed the tables to DEF. The DDL
I sent are production tables. I was trying to change the names, etc, but
decided to send you the live information. Thus far, no one has been able to
help explain why I cannot delete and recreate constraints in a sp or script
or dts on tables that have records. The irony is that this thing worked the
first few times and just fails thereafter -- requiring me to recreate the
constraints manually.
I am still waiting for your support.
Thanks.
Stoko.
"Tom Moreau" wrote:

> Actually, we really need the DDL for table dbo.DEF.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com
> ..
> "stoko" <stoko@.discussions.microsoft.com> wrote in message
> news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
> Below is the info you requested. Each time I drop the constraints via sql
> analyzer and try recreating them, I have the FK error. I check via EM and
> the constraints are not there. What must be going on is beyond my
> comprehension. Initially, the first 4 attempts works fine but
there-after,
> nothing works. Remember that the tables have data.
> Let me know...
> Thanks in advance.
> Stoko.
> "Tom Moreau" wrote:
>
>sql

ALTER TABLE statement conflicted with COLUMN FOREIGN KEY

I got the following Error
"ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
constraint 'FK_ABC_DEF'. The conflict occurred in
database 'Test', table 'DEF', column 'ID'."
when I ran the following scripts:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
GO
ALTER TABLE [dbo].[ABC] ADD
CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
(
[ID]
) REFERENCES [dbo].[DEF] (
[ID]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
My goal was to delete the constraint and recreate it but
the above error indicates that the FK constraint is still
active even when I verified on both tables and there were
not available.
Is this a problem with sqlserver 2000 or the problem is me.
Please help.Post your DDL for table dbo.DEF.
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:0ba901c48936$784343d0$3501280a@.phx.gbl...
I got the following Error
"ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
constraint 'FK_ABC_DEF'. The conflict occurred in
database 'Test', table 'DEF', column 'ID'."
when I ran the following scripts:
if exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
GO
ALTER TABLE [dbo].[ABC] ADD
CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
(
[ID]
) REFERENCES [dbo].[DEF] (
[ID]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
My goal was to delete the constraint and recreate it but
the above error indicates that the FK constraint is still
active even when I verified on both tables and there were
not available.
Is this a problem with sqlserver 2000 or the problem is me.
Please help.|||Perhaps you have existing data that prevents the new constraint from being
created. You can identify this data with the query below:
SELECT *
FROM [dbo].[ABC] AS a
WHERE NOT EXISTS
(
SELECT *
FROM [dbo].[DEF] AS b
WHERE a.[ID] = b.[ID]
)
--
Hope this helps.
Dan Guzman
SQL Server MVP
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id => object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>|||Actually, we really need the DDL for table dbo.DEF.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
.
"stoko" <stoko@.discussions.microsoft.com> wrote in message
news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
"Tom Moreau" wrote:
> Post your DDL for table dbo.DEF.
> --
> Tom
> ---
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id => object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>|||On Wed, 8 Sep 2004 12:15:05 -0700, stoko wrote:
>Below is the info you requested. Each time I drop the constraints via sql
>analyzer and try recreating them, I have the FK error. I check via EM and
>the constraints are not there. What must be going on is beyond my
>comprehension. Initially, the first 4 attempts works fine but there-after,
>nothing works. Remember that the tables have data.
>Let me know...
>Thanks in advance.
>Stoko.
(snip code)
Hi Stoko,
The code you supplied works fine for me. And when I append the code from
your original post, I get the following error:
Server: Msg 4902, Level 16, State 1, Line 3
Cannot alter table 'dbo.ABC' because this table does not exist in database
'TestDB80'.
Somehow, you seem to have posted the wrong tables here.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||It will save you even more time if you simply provide the DDL for BOTH
tables. I cannot help you until you do that.
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"stoko" <stoko@.discussions.microsoft.com> wrote in message
news:F2F57F9B-D3E5-4B47-A53E-4A2F2750E2FB@.microsoft.com...
Tom,
It would have saved us some time if you renamed the tables to DEF. The DDL
I sent are production tables. I was trying to change the names, etc, but
decided to send you the live information. Thus far, no one has been able to
help explain why I cannot delete and recreate constraints in a sp or script
or dts on tables that have records. The irony is that this thing worked the
first few times and just fails thereafter -- requiring me to recreate the
constraints manually.
I am still waiting for your support.
Thanks.
Stoko.
"Tom Moreau" wrote:
> Actually, we really need the DDL for table dbo.DEF.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com
> ..
> "stoko" <stoko@.discussions.microsoft.com> wrote in message
> news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
> Below is the info you requested. Each time I drop the constraints via sql
> analyzer and try recreating them, I have the FK error. I check via EM and
> the constraints are not there. What must be going on is beyond my
> comprehension. Initially, the first 4 attempts works fine but
there-after,
> nothing works. Remember that the tables have data.
> Let me know...
> Thanks in advance.
> Stoko.
> "Tom Moreau" wrote:
> > Post your DDL for table dbo.DEF.
> >
> > --
> > Tom
> >
> > ---
> > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> > SQL Server MVP
> > Columnist, SQL Server Professional
> > Toronto, ON Canada
> > www.pinnaclepublishing.com/sql
> >
> >
> > "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> > news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> > I got the following Error
> >
> > "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> > constraint 'FK_ABC_DEF'. The conflict occurred in
> > database 'Test', table 'DEF', column 'ID'."
> >
> > when I ran the following scripts:
> >
> > if exists (select * from dbo.sysobjects where id => > object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> > N'IsForeignKey') = 1)
> > ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> > GO
> >
> >
> > ALTER TABLE [dbo].[ABC] ADD
> > CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> > (
> > [ID]
> > ) REFERENCES [dbo].[DEF] (
> > [ID]
> > ) ON DELETE CASCADE NOT FOR REPLICATION
> > GO
> >
> >
> > My goal was to delete the constraint and recreate it but
> > the above error indicates that the FK constraint is still
> > active even when I verified on both tables and there were
> > not available.
> >
> > Is this a problem with sqlserver 2000 or the problem is me.
> >
> > Please help.
> >
> >
> >
>

ALTER TABLE statement conflicted with COLUMN FOREIGN KEY

I got the following Error
"ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
constraint 'FK_ABC_DEF'. The conflict occurred in
database 'Test', table 'DEF', column 'ID'."
when I ran the following scripts:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
GO
ALTER TABLE [dbo].[ABC] ADD
CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
(
[ID]
) REFERENCES [dbo].[DEF] (
[ID]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
My goal was to delete the constraint and recreate it but
the above error indicates that the FK constraint is still
active even when I verified on both tables and there were
not available.
Is this a problem with sqlserver 2000 or the problem is me.
Please help.
Post your DDL for table dbo.DEF.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:0ba901c48936$784343d0$3501280a@.phx.gbl...
I got the following Error
"ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
constraint 'FK_ABC_DEF'. The conflict occurred in
database 'Test', table 'DEF', column 'ID'."
when I ran the following scripts:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
GO
ALTER TABLE [dbo].[ABC] ADD
CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
(
[ID]
) REFERENCES [dbo].[DEF] (
[ID]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
My goal was to delete the constraint and recreate it but
the above error indicates that the FK constraint is still
active even when I verified on both tables and there were
not available.
Is this a problem with sqlserver 2000 or the problem is me.
Please help.
|||Perhaps you have existing data that prevents the new constraint from being
created. You can identify this data with the query below:
SELECT *
FROM [dbo].[ABC] AS a
WHERE NOT EXISTS
(
SELECT *
FROM [dbo].[DEF] AS b
WHERE a.[ID] = b.[ID]
)
Hope this helps.
Dan Guzman
SQL Server MVP
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
|||Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
"Tom Moreau" wrote:

> Post your DDL for table dbo.DEF.
> --
> Tom
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>
|||Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_AliasIDtb_RecipDemotb]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[AliasIDtb] DROP CONSTRAINT FK_AliasIDtb_RecipDemotb
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_CMStb_RecipDemotb]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CMStb] DROP CONSTRAINT FK_CMStb_RecipDemotb
GO
CREATE TABLE [dbo].[RecipDemotb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[RecipSSN] [numeric](18, 0) NULL ,
[RecipLastNM] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipFirstNM] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipMiddleNM] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipSuffix] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipPhone] [numeric](10, 0) NULL ,
[RecipDOB] [datetime] NULL ,
[RecipDOD] [datetime] NULL ,
[RecipAddress] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipAddress2] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipCounty] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipState] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipZip] [numeric](11, 0) NULL ,
[RecipRace] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MedIDNM] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EPSDTIND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipSex] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[TPLIND] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipNMCD] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipDOE] [datetime] NULL ,
[RecipIDNUM] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Buy_In_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Dup_Card_Code] [tinyint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[AliasIDtb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[MAID] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IdBeginDate] [datetime] NULL ,
[IdEndDate] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[CMStb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[CMS_PART_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CMS_Beg_Date] [datetime] NULL ,
[CMS_End_Date] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RecipDemotb] WITH NOCHECK ADD
CONSTRAINT [PK_RecipDemotb] PRIMARY KEY CLUSTERED
(
[OriginalRecipid]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[AliasIDtb] ADD
CONSTRAINT [FK_AliasIDtb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[CMStb] ADD
CONSTRAINT [FK_CMStb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
"Tom Moreau" wrote:

> Post your DDL for table dbo.DEF.
> --
> Tom
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>
|||Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_AliasIDtb_RecipDemotb]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[AliasIDtb] DROP CONSTRAINT FK_AliasIDtb_RecipDemotb
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_CMStb_RecipDemotb]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CMStb] DROP CONSTRAINT FK_CMStb_RecipDemotb
GO
CREATE TABLE [dbo].[RecipDemotb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[RecipSSN] [numeric](18, 0) NULL ,
[RecipLastNM] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipFirstNM] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipMiddleNM] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipSuffix] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipPhone] [numeric](10, 0) NULL ,
[RecipDOB] [datetime] NULL ,
[RecipDOD] [datetime] NULL ,
[RecipAddress] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipAddress2] [varchar] (22) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipCounty] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipState] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipZip] [numeric](11, 0) NULL ,
[RecipRace] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MedIDNM] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EPSDTIND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipSex] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[TPLIND] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipNMCD] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RecipDOE] [datetime] NULL ,
[RecipIDNUM] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Buy_In_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Dup_Card_Code] [tinyint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[AliasIDtb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[MAID] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IdBeginDate] [datetime] NULL ,
[IdEndDate] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[CMStb] (
[OriginalRecipid] [char] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[CMS_PART_IND] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CMS_Beg_Date] [datetime] NULL ,
[CMS_End_Date] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RecipDemotb] WITH NOCHECK ADD
CONSTRAINT [PK_RecipDemotb] PRIMARY KEY CLUSTERED
(
[OriginalRecipid]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[AliasIDtb] ADD
CONSTRAINT [FK_AliasIDtb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[CMStb] ADD
CONSTRAINT [FK_CMStb_RecipDemotb] FOREIGN KEY
(
[OriginalRecipid]
) REFERENCES [dbo].[RecipDemotb] (
[OriginalRecipid]
) ON DELETE CASCADE NOT FOR REPLICATION
GO
"Dan Guzman" wrote:

> Perhaps you have existing data that prevents the new constraint from being
> created. You can identify this data with the query below:
> SELECT *
> FROM [dbo].[ABC] AS a
> WHERE NOT EXISTS
> (
> SELECT *
> FROM [dbo].[DEF] AS b
> WHERE a.[ID] = b.[ID]
> )
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
>
>
|||Actually, we really need the DDL for table dbo.DEF.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
..
"stoko" <stoko@.discussions.microsoft.com> wrote in message
news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
Below is the info you requested. Each time I drop the constraints via sql
analyzer and try recreating them, I have the FK error. I check via EM and
the constraints are not there. What must be going on is beyond my
comprehension. Initially, the first 4 attempts works fine but there-after,
nothing works. Remember that the tables have data.
Let me know...
Thanks in advance.
Stoko.
"Tom Moreau" wrote:

> Post your DDL for table dbo.DEF.
> --
> Tom
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com/sql
>
> "stoko" <anonymous@.discussions.microsoft.com> wrote in message
> news:0ba901c48936$784343d0$3501280a@.phx.gbl...
> I got the following Error
> "ALTER TABLE statement conflicted with COLUMN FOREIGN KEY
> constraint 'FK_ABC_DEF'. The conflict occurred in
> database 'Test', table 'DEF', column 'ID'."
> when I ran the following scripts:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[FK_ABC_DEF]') and OBJECTPROPERTY(id,
> N'IsForeignKey') = 1)
> ALTER TABLE [dbo].[ABC] DROP CONSTRAINT FK_ABC_DEF
> GO
>
> ALTER TABLE [dbo].[ABC] ADD
> CONSTRAINT [FK_ABC_DEF] FOREIGN KEY
> (
> [ID]
> ) REFERENCES [dbo].[DEF] (
> [ID]
> ) ON DELETE CASCADE NOT FOR REPLICATION
> GO
>
> My goal was to delete the constraint and recreate it but
> the above error indicates that the FK constraint is still
> active even when I verified on both tables and there were
> not available.
> Is this a problem with sqlserver 2000 or the problem is me.
> Please help.
>
>
|||On Wed, 8 Sep 2004 12:15:05 -0700, stoko wrote:

>Below is the info you requested. Each time I drop the constraints via sql
>analyzer and try recreating them, I have the FK error. I check via EM and
>the constraints are not there. What must be going on is beyond my
>comprehension. Initially, the first 4 attempts works fine but there-after,
>nothing works. Remember that the tables have data.
>Let me know...
>Thanks in advance.
>Stoko.
(snip code)
Hi Stoko,
The code you supplied works fine for me. And when I append the code from
your original post, I get the following error:
Server: Msg 4902, Level 16, State 1, Line 3
Cannot alter table 'dbo.ABC' because this table does not exist in database
'TestDB80'.
Somehow, you seem to have posted the wrong tables here.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Tom,
It would have saved us some time if you renamed the tables to DEF. The DDL
I sent are production tables. I was trying to change the names, etc, but
decided to send you the live information. Thus far, no one has been able to
help explain why I cannot delete and recreate constraints in a sp or script
or dts on tables that have records. The irony is that this thing worked the
first few times and just fails thereafter -- requiring me to recreate the
constraints manually.
I am still waiting for your support.
Thanks.
Stoko.
"Tom Moreau" wrote:

> Actually, we really need the DDL for table dbo.DEF.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com
> ..
> "stoko" <stoko@.discussions.microsoft.com> wrote in message
> news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
> Below is the info you requested. Each time I drop the constraints via sql
> analyzer and try recreating them, I have the FK error. I check via EM and
> the constraints are not there. What must be going on is beyond my
> comprehension. Initially, the first 4 attempts works fine but there-after,
> nothing works. Remember that the tables have data.
> Let me know...
> Thanks in advance.
> Stoko.
> "Tom Moreau" wrote:
>
>
|||It will save you even more time if you simply provide the DDL for BOTH
tables. I cannot help you until you do that.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"stoko" <stoko@.discussions.microsoft.com> wrote in message
news:F2F57F9B-D3E5-4B47-A53E-4A2F2750E2FB@.microsoft.com...
Tom,
It would have saved us some time if you renamed the tables to DEF. The DDL
I sent are production tables. I was trying to change the names, etc, but
decided to send you the live information. Thus far, no one has been able to
help explain why I cannot delete and recreate constraints in a sp or script
or dts on tables that have records. The irony is that this thing worked the
first few times and just fails thereafter -- requiring me to recreate the
constraints manually.
I am still waiting for your support.
Thanks.
Stoko.
"Tom Moreau" wrote:

> Actually, we really need the DDL for table dbo.DEF.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinnaclepublishing.com
> ..
> "stoko" <stoko@.discussions.microsoft.com> wrote in message
> news:72208196-B2EE-4A61-B46C-0F9C7DA0AAE6@.microsoft.com...
> Below is the info you requested. Each time I drop the constraints via sql
> analyzer and try recreating them, I have the FK error. I check via EM and
> the constraints are not there. What must be going on is beyond my
> comprehension. Initially, the first 4 attempts works fine but
there-after,
> nothing works. Remember that the tables have data.
> Let me know...
> Thanks in advance.
> Stoko.
> "Tom Moreau" wrote:
>
>

Alter Table Row Size Error

I am trying to alter a table and getting the following error.
Server: Msg 1701, Level 16, State 2, Line 1
Creation of table 'CustomerMaster' failed because the row size would be
8508, including internal overhead. This exceeds the maximum allowable table
row size, 8060.
I can create a new table with the same fields, but not alter an existing one.
I have calculated the maximum row size as only 6004 after the changes. Here
is what I used to calculate.
69 columns
39 char fields (5816 total characters)
9 tinyint fields (size = 9 * 1 = 9)
4 int fields (size = 4 * 4 = 16)
5 datetime fields (size = 5 * 8 = 40)
12 decimal 19,5 fields (size = 12 * 9 = 108)
Num_Cols = 69
Fixed_Data_Size = 5989
Num_Var_Cols = 0
Max_Var_Size = 0
Null_Bitmap = 2 + ((69 + 7 ) / 8 = 11.5
Row_Size = 5981 + 0 + 11 + 4 = 6004> 39 char fields (5816 total characters)
What are the definitions of these columns? Are they
CHAR/NCHAR/VARCHAR/NVARCHAR? What size? Are they NULLable?
> 9 tinyint fields (size = 9 * 1 = 9)
> 4 int fields (size = 4 * 4 = 16)
> 5 datetime fields (size = 5 * 8 = 40)
> 12 decimal 19,5 fields (size = 12 * 9 = 108)
Are any of these NULLable?|||"Aaron Bertrand [SQL Server MVP]" wrote:
> > 39 char fields (5816 total characters)
> What are the definitions of these columns? Are they
> CHAR/NCHAR/VARCHAR/NVARCHAR? What size? Are they NULLable?
> > 9 tinyint fields (size = 9 * 1 = 9)
> > 4 int fields (size = 4 * 4 = 16)
> > 5 datetime fields (size = 5 * 8 = 40)
> > 12 decimal 19,5 fields (size = 12 * 9 = 108)
> Are any of these NULLable?
>
>
39 CHAR fields
field length - field count
3 - 2
5 - 3
10 - 4
15 - 1
20 - 11
25 - 2
30 - 11
45 - 2
50 - 1
2000 - 1
3000 - 1
total characters = 5816
all fields are NULLABLE but one CHAR field (in my calculations I considered
all fields as nullable)|||"Aaron Bertrand [SQL Server MVP]" wrote:
> > 39 char fields (5816 total characters)
> What are the definitions of these columns? Are they
> CHAR/NCHAR/VARCHAR/NVARCHAR? What size? Are they NULLable?
> > 9 tinyint fields (size = 9 * 1 = 9)
> > 4 int fields (size = 4 * 4 = 16)
> > 5 datetime fields (size = 5 * 8 = 40)
> > 12 decimal 19,5 fields (size = 12 * 9 = 108)
> Are any of these NULLable?
>
>
I used http://msdn2.microsoft.com/en-us/library/aa933068(SQL.80).aspx to
calculate my row size.|||Are you certain they're all CHAR and none are NCHAR or NVARCHAR? Can you
post the results of:
EXEC sp_help 'tablename';
?
Why would you have a CHAR(2000) or CHAR(3000)? Is every row always going to
be 3000 characters?
"Matt Soukup" <MattSoukup@.discussions.microsoft.com> wrote in message
news:F6ADF63E-E3FD-4D8E-88C7-8D1B1C4F2D22@.microsoft.com...
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>> > 39 char fields (5816 total characters)
>> What are the definitions of these columns? Are they
>> CHAR/NCHAR/VARCHAR/NVARCHAR? What size? Are they NULLable?
>> > 9 tinyint fields (size = 9 * 1 = 9)
>> > 4 int fields (size = 4 * 4 = 16)
>> > 5 datetime fields (size = 5 * 8 = 40)
>> > 12 decimal 19,5 fields (size = 12 * 9 = 108)
>> Are any of these NULLable?
>>
> 39 CHAR fields
> field length - field count
> 3 - 2
> 5 - 3
> 10 - 4
> 15 - 1
> 20 - 11
> 25 - 2
> 30 - 11
> 45 - 2
> 50 - 1
> 2000 - 1
> 3000 - 1
> total characters = 5816
> all fields are NULLABLE but one CHAR field (in my calculations I
> considered
> all fields as nullable)|||> I used http://msdn2.microsoft.com/en-us/library/aa933068(SQL.80).aspx to
> calculate my row size.
Yes, that's all fine and good. But if you wrote down CHAR(3000) when it's
actually NCHAR(3000), and used the former in your calculations, it doesn't
really matter how accurate the calculation is, the source input invalidates
it.|||"Aaron Bertrand [SQL Server MVP]" wrote:
> > I used http://msdn2.microsoft.com/en-us/library/aa933068(SQL.80).aspx to
> > calculate my row size.
> Yes, that's all fine and good. But if you wrote down CHAR(3000) when it's
> actually NCHAR(3000), and used the former in your calculations, it doesn't
> really matter how accurate the calculation is, the source input invalidates
> it.
>
>
all character fields are CHAR(####)
Nothing is NCHAR, VARCHAR, NVARCHAR, etc...
Here is a list of the fields:
Customer_Number char(20)
CUSTNMBR char(45)
VENDORID char(45)
Attn_Name char(30)
Contact_Name char(30)
ContactPhone char(20)
BusinessName char(30)
AddressLine1 char(30)
AddressLine2 char(30)
City char(25)
State char(3)
ZipCode char(10)
Phone char(20)
Fax char(20)
ICC_Number char(20)
FedID_Number char(15)
Contracted tinyint
Start_Date datetime
InsAgentName char(30)
InsAgentAddress1 char(30)
InsAgentAddress2 char(30)
InsAgentCity char(25)
InsAgentState char(3)
InsAgentZipCode char(10)
InsAgentPhone char(20)
InsAgentFax char(20)
InsAgentContact char(30)
CargoInsName char(28)
CargoInsAmount decimal(19, 5)
CargoInsExpirationDate datetime
AutoLibInsName char(30)
AutoLibInsAmount decimal(19, 5)
AutoLibInsExpirationDate datetime
Agent_YN tinyint
Broker_YN tinyint
Carrier_YN tinyint
Shipper_YN tinyint
Consignee_YN tinyint
BillTo_YN tinyint
CreatedDate datetime
CreatedUserID char(20)
Billing_Rate decimal(19, 5)
Billing_Rate_Code char(5)
Rating char(5)
Color char(20)
Flagged tinyint
FlagDate datetime
FlagUserID char(20)
FlagReason char(50)
Active tinyint
Notes char(3000)
PayCode char(5)
PayRateFlat decimal(19, 5)
PayRatePercent decimal(19, 5)
PayRateLoaded decimal(19, 5)
PayRateUnloaded decimal(19, 5)
DefaultSalesperson char(20)
Directions char(2000)
FSType char(10)
FSRateAmount decimal(19, 5)
Weight decimal(19, 5)
AgentPayAccount int
CarrierPayAccount int
DropPayAmount decimal(19, 5)
PickupPayAmount decimal(19, 5)
ISType char(10)
ISRateAmount decimal(19, 5)
Latitude int
Longitude int|||Sorry, but there is still information missing. I don't want to see your
compiled list of fields. Can you please copy and paste the result of:
EXEC sp_help 'CustomerMaster';
? Otherwise, I have no further input on this issue. The list of columns
you provided below can't possibly be 8508 bytes unless (a) the column you're
trying to add is a lot longer than you're letting on, (b) some of those data
types are not correct, or (c) you've left out some columns.
> all character fields are CHAR(####)
> Nothing is NCHAR, VARCHAR, NVARCHAR, etc...
> Here is a list of the fields:
> Customer_Number char(20)|||"Aaron Bertrand [SQL Server MVP]" wrote:
> Sorry, but there is still information missing. I don't want to see your
> compiled list of fields. Can you please copy and paste the result of:
> EXEC sp_help 'CustomerMaster';
> ? Otherwise, I have no further input on this issue. The list of columns
> you provided below can't possibly be 8508 bytes unless (a) the column you're
> trying to add is a lot longer than you're letting on, (b) some of those data
> types are not correct, or (c) you've left out some columns.
>
>
> > all character fields are CHAR(####)
> > Nothing is NCHAR, VARCHAR, NVARCHAR, etc...
> >
> > Here is a list of the fields:
> >
> > Customer_Number char(20)
>
>
Just forget it. SQL is being stupid.
This error is being posted when I try to ALTER TABLE CustomerMaster ALTER
COLUMN "ContactPhone" CHAR(20). Changing it from CHAR(10) to CHAR(20).
I can create this table from scratch with the columns/sizes I listed above.
The table is created with no problem. I have to up the size of one of my CHAR
fields by 3000, change Directions from CHAR(2000) to CHAR(5000), to get the
CREATE TABLE to fail with the same error.|||> Just forget it. SQL is being stupid.
I am willing to bet that it is not. But I can't prove it unless you post an
honest result from EXEC sp_help.
> This error is being posted when I try to ALTER TABLE CustomerMaster ALTER
> COLUMN "ContactPhone" CHAR(20). Changing it from CHAR(10) to CHAR(20).
Is it possible this column is involved in a foreign key relationship, and
you are trying to implement the change through the GUI?
A|||> I can create this table from scratch with the columns/sizes I listed
> above.
> The table is created with no problem. I have to up the size of one of my
> CHAR
> fields by 3000, change Directions from CHAR(2000) to CHAR(5000), to get
> the
> CREATE TABLE to fail with the same error.
I also strongly recommend you familiarize yourself with the reasons we have
CHAR and VARCHAR. CHAR(2000) is not exactly a great choice here.
http://databases.aspfaq.com/database/what-datatype-should-i-use-for-my-character-based-database-columns.html
A|||Hi Matt
If you ALTER the length of fixed length columns, SQL Server may not reuse
the original space.
See my blog post on the subject:
http://sqlblog.com/blogs/kalen_delaney/archive/2006/10/13/301.aspx
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Matt Soukup" <MattSoukup@.discussions.microsoft.com> wrote in message
news:9EF8C9DF-A8DE-406D-B1BA-1C67338D8FB3@.microsoft.com...
>I am trying to alter a table and getting the following error.
> Server: Msg 1701, Level 16, State 2, Line 1
> Creation of table 'CustomerMaster' failed because the row size would be
> 8508, including internal overhead. This exceeds the maximum allowable
> table
> row size, 8060.
> I can create a new table with the same fields, but not alter an existing
> one.
> I have calculated the maximum row size as only 6004 after the changes.
> Here
> is what I used to calculate.
> 69 columns
> 39 char fields (5816 total characters)
> 9 tinyint fields (size = 9 * 1 = 9)
> 4 int fields (size = 4 * 4 = 16)
> 5 datetime fields (size = 5 * 8 = 40)
> 12 decimal 19,5 fields (size = 12 * 9 = 108)
> Num_Cols = 69
> Fixed_Data_Size = 5989
> Num_Var_Cols = 0
> Max_Var_Size = 0
> Null_Bitmap = 2 + ((69 + 7 ) / 8 = 11.5
> Row_Size = 5981 + 0 + 11 + 4 = 6004
>|||On Feb 7, 2:13 pm, Matt Soukup <MattSou...@.discussions.microsoft.com>
wrote:
> Just forget it. SQL is being stupid.
> This error is being posted when I try to ALTER TABLE CustomerMaster ALTER
> COLUMN "ContactPhone" CHAR(20). Changing it from CHAR(10) to CHAR(20).
> I can create this table from scratch with the columns/sizes I listed above.
> The table is created with no problem. I have to up the size of one of my CHAR
> fields by 3000, change Directions from CHAR(2000) to CHAR(5000), to get the
> CREATE TABLE to fail with the same error.
Aaron asked you twice for the results of sp_help, and you've refused
to provide that, instead opting for the "SQL is being stupid"
response. WTF? If we can see the table structure, then we know
exactly what you're working with, and can provide a proper answer
instead of guessing.
Here's another suggestion that you can write off as "stupid" - think
about using VARCHAR instead of CHAR for your column definitions.
You're very likely wasting a ton of space with these fixed-length
2000+ column lengths. Read up on the differences between CHAR and
VARCHAR, hopefully the documentation isn't too "stupid".|||This may very well be it; I'm glad I cntinue to learn things from you Kalen.
But the OP stated:
"This error is being posted when I try to ALTER TABLE CustomerMaster ALTER
COLUMN "ContactPhone" CHAR(20). Changing it from CHAR(10) to CHAR(20)."
Yet is able to increase the length of a CHAR(2000) column to CHAR(5000). I
would think that if previous column modifications had caused the row size
threshold to be within 10 bytes of the current row size, that just about
*any* column length extension would cause the problem. I guess having the
actual table structure from sp_help, so understanding the order of the
columns (and a history of modifications made) would help us answer the
question better. Better still would be the result of your query against
sys.partitions/columns/system_internals_partition_columns.
In any case, the last statement in your blog entry is probably the most
helpful to the OP, though Tracy and I have both suggested it to no avail:
"So be careful when using large datatypes, especially if you want to make
them fixed length instead of variable length."
The shortest path is likely to rebuild the table. But the Directions and
Notes columns should be VARCHAR, not CHAR.
A
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:e5yhB40SHHA.1552@.TK2MSFTNGP05.phx.gbl...
> Hi Matt
> If you ALTER the length of fixed length columns, SQL Server may not reuse
> the original space.
> See my blog post on the subject:
> http://sqlblog.com/blogs/kalen_delaney/archive/2006/10/13/301.aspx|||I didn't read the whole thread in detail initially, I was just tossing this
out as a possibility.
However, now that I am going back and reading over the posts, I don't see
anywhere that he said he had already altered the table changing a column
from 2000 to 5000 bytes. He said he would have to replace a 2000 byte column
with a 5000 byte column to get the original CREATE TABLE to fail. Has he
indicated he has done other ALTERs?
Yes, it would be nice to get more details from the OP, including WHY he
thinks he needs fixed length columns. Otherwise we just can't know. I agree
Directions and Notes should be variable length.
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OpFCoZ4SHHA.1552@.TK2MSFTNGP05.phx.gbl...
> This may very well be it; I'm glad I cntinue to learn things from you
> Kalen.
> But the OP stated:
> "This error is being posted when I try to ALTER TABLE CustomerMaster ALTER
> COLUMN "ContactPhone" CHAR(20). Changing it from CHAR(10) to CHAR(20)."
> Yet is able to increase the length of a CHAR(2000) column to CHAR(5000).
> I would think that if previous column modifications had caused the row
> size threshold to be within 10 bytes of the current row size, that just
> about *any* column length extension would cause the problem. I guess
> having the actual table structure from sp_help, so understanding the order
> of the columns (and a history of modifications made) would help us answer
> the question better. Better still would be the result of your query
> against sys.partitions/columns/system_internals_partition_columns.
> In any case, the last statement in your blog entry is probably the most
> helpful to the OP, though Tracy and I have both suggested it to no avail:
> "So be careful when using large datatypes, especially if you want to make
> them fixed length instead of variable length."
> The shortest path is likely to rebuild the table. But the Directions and
> Notes columns should be VARCHAR, not CHAR.
> A
>
>
>
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:e5yhB40SHHA.1552@.TK2MSFTNGP05.phx.gbl...
>> Hi Matt
>> If you ALTER the length of fixed length columns, SQL Server may not reuse
>> the original space.
>> See my blog post on the subject:
>> http://sqlblog.com/blogs/kalen_delaney/archive/2006/10/13/301.aspx
>|||> However, now that I am going back and reading over the posts, I don't see
> anywhere that he said he had already altered the table changing a column
> from 2000 to 5000 bytes. He said he would have to replace a 2000 byte
> column with a 5000 byte column to get the original CREATE TABLE to fail.
> Has he indicated he has done other ALTERs?
Here is what I am referring to:
I have to up the size of one of my CHAR
fields by 3000, change Directions from CHAR(2000) to CHAR(5000), to get the
CREATE TABLE to fail with the same error.
My interpretation was that he had done that. Maybe I'm wrong. It's
ambiguous.
A|||Yes, that is what I'm referring to, and he explicitly says it is the CREATE
table and not ALTER.
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:%23UIpXh6SHHA.2228@.TK2MSFTNGP03.phx.gbl...
>> However, now that I am going back and reading over the posts, I don't see
>> anywhere that he said he had already altered the table changing a column
>> from 2000 to 5000 bytes. He said he would have to replace a 2000 byte
>> column with a 5000 byte column to get the original CREATE TABLE to fail.
>> Has he indicated he has done other ALTERs?
> Here is what I am referring to:
> I have to up the size of one of my CHAR
> fields by 3000, change Directions from CHAR(2000) to CHAR(5000), to get
> the
> CREATE TABLE to fail with the same error.
> My interpretation was that he had done that. Maybe I'm wrong. It's
> ambiguous.
> A
>|||> Yes, that is what I'm referring to, and he explicitly says it is the
> CREATE table and not ALTER.
Ahh. You should know by now that I lack the ability to read entire
sentences. :-)
And you would think the caps would make words stand out more, but for me it
obscures them... I tend to focus on the meat *between* the keywords...
A