I am converting IIF statements from an Access Query into a Stored Procedure
and was doing ok until I got to this one which is a bit more complicated:
CASE WHEN [Field1] = 1 THEN 0 ELSE [Field2] + [Field3] -[Field4] / [Field5]
END
All fields are valid boleen fields
I have tried putting parens around the equation part but still get errors.
How can I get the data into this field? Thanks.CAST as the bit columns as INT such as CAST([Field2] AS INT)
I think that [Field2] + [Field3] -[Field4] / [Field5]
should be ([Field2] + [Field3] -[Field4]) / [Field5]
"AkAlan" <AkAlan@.discussions.microsoft.com> wrote in message
news:F23EB696-E2B4-43EA-AC88-664FB8B2221E@.microsoft.com...
>I am converting IIF statements from an Access Query into a Stored
>Procedure
> and was doing ok until I got to this one which is a bit more complicated:
> CASE WHEN [Field1] = 1 THEN 0 ELSE [Field2] + [Field3] -[Field4] /
> [Field5]
> END
> All fields are valid boleen fields
> I have tried putting parens around the equation part but still get errors.
> How can I get the data into this field? Thanks.
>|||Please explain what "All fields are valid boleen fields" means.
Also post the error message that you get.
ML|||The Fields I'm trying to perform math on are boolean fields and are already
in place in the stored procedure.
The error says:
ADO Error:Invalid operator for data type. Operator equals add, type equals
bit.
Thanks for helping.
"ML" wrote:
> Please explain what "All fields are valid boleen fields" means.
> Also post the error message that you get.
>
> ML|||>> All fields are valid Boolean fields <<
UNH' Let's get back to the basics of an RDBMS. Rows are not records;
fields are not columns; tables are not files.
Where is the DDL? SQL has no Boolean data types and good programemrs
do not use the proprietary BIT data type.
There is no CASE statement in SQL, either; there is a CASE expression.
So what "field" are you trying to assign this exprsssion to?|||First of all, bit is not boolean, and second - the error message is pretty
much self-explanatory. Why are you adding, subtracting and dividing values
that can either be 1 or 0?
E.g.:
what does this mean to you:
1 + 0 - 1 / 1
or:
1 + 1 - 0 / 1
or worse:
1 + 1 -1 / 0
Please describe what you're trying to achieve. There must be some reason...?
ML|||
"ML" wrote:
> First of all, bit is not boolean, and second - the error message is pretty
> much self-explanatory. Why are you adding, subtracting and dividing values
> that can either be 1 or 0?
> E.g.:
> what does this mean to you:
> 1 + 0 - 1 / 1...this means 0%
> 1 + 0 / 1 + 1 ...this would be 50%
> 1 + 1 / 1 + 1 ...100%
> or:
> 1 + 1 - 0 / 1
> or worse:
> 1 + 1 -1 / 0...checked for and not allowed through business rules
> Please describe what you're trying to achieve. There must be some reason..
.?
>
> ML
I needed to be able to do math on the fields like I can in MS
Access...Changing the bits to integers worked.|||> Where is the DDL? SQL has no Boolean data types and good programemrs
> do not use the proprietary BIT data type.
Good programmers make proper use of approriate dtaa types in any given
situation.
Similary, good programmers don't just follow along with the comment "all
GOTO statements or CURSORs are bad", but take the time to understand why
other programmers prefer to use better alternatives. Cursors can also be
very powerful, but only when used in an appropriate situation where the same
result cannot be equally-well achieved via set-based operations.
If you were defining a table ApplicationUsers, and needed to store (in a
SQL2000 database) a field indicating whether the user was enabled, ( a field
that could only ever have a value of Yes/No), what field would YOU use ...
> There is no CASE statement in SQL, either; there is a CASE expression.
> So what "field" are you trying to assign this exprsssion to?
Whilst I agree with you that the snippet is technically an expression, not a
statement, this value doesn't necessarily need to be assigned to a field.|||I guess if I were an SQL expert I wouldn't need to use this web site and
expose my ignorance of SQL terminology to arrogant know-it-alls who find it
easier to berate my lack of knowledge than just simply give me the answer I
was looking for like Raymond D'Anjou so kindly did. I would appreciate you
not anwering any of my posts in the future.
"--CELKO--" wrote:
> UNH' Let's get back to the basics of an RDBMS. Rows are not records;
> fields are not columns; tables are not files.
> Where is the DDL? SQL has no Boolean data types and good programemrs
> do not use the proprietary BIT data type.
> There is no CASE statement in SQL, either; there is a CASE expression.
> So what "field" are you trying to assign this exprsssion to?
>|||AkAlan,
Don't let Celko intimidate you, and as for him being a SQL expert, well,
perhaps an ANSI 92 expert and thats about as far as it goes.
Tony.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"AkAlan" <AkAlan@.discussions.microsoft.com> wrote in message
news:0A58D8F7-6E39-4072-9634-2082745BA421@.microsoft.com...
>I guess if I were an SQL expert I wouldn't need to use this web site and
> expose my ignorance of SQL terminology to arrogant know-it-alls who find
> it
> easier to berate my lack of knowledge than just simply give me the answer
> I
> was looking for like Raymond D'Anjou so kindly did. I would appreciate you
> not anwering any of my posts in the future.
> "--CELKO--" wrote:
>
Showing posts with label converting. Show all posts
Showing posts with label converting. Show all posts
Thursday, March 29, 2012
Case Statement in Stored Procedure ?
Sunday, March 11, 2012
Cascading Changes in SQL Server
I am converting a database from Access to SQL Server and am trying to
set up a relationship like the one that had been set in Access. This
relationship had cascading deletes and updates. When I try to set up
the relationship in SQL server, I get the message (as an example):
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
FOREIGN KEY constraint 'FK_States-StateID' on table
'PersonnelInformation' may cause cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
I don't really understand why I am getting this message, unless
cascading updates are bidirectional (meaning that a change to the
foreign key would cascade over to the primary key:
I basically have the following setup (I am using an example that is a
bit easier to understand than my actual table setup:
TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
CompanyTaxID CompanyTaxID StateID CompanyTaxID
Company CEOName STATE SubsidiaryTaxID
StateID AddressLine1 StateID
...
StateID
So basically I set a primary key to foreign key relationship from
TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
and Updates).
I also set a primary to foreign Key relationship from TABLECOMPANY
(PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
and Updates).
Then I create a primary to foreign key relationship from TABLESTATE
(PK) to Each of the other three tables on StateID (Update only).
This configuration fails. I don't understand why, though clearly the
relationships with TABLESTATE are the problem. But since TABLE state
contains no foreign keys, nor does it specify any cascading deletes,
no changes made anywhere could create a loop. Unless a change in a
foreign key could affect the primary key, which doesn't make
sense...?
Does anyone know why this is happening. Is there a solution, or do I
HAVE to use triggers?
Thanks,
Ryan
Check the article at
http://support.microsoft.com/default...;en-us;321843, it is about
this error.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Ryan" <ryan.d.rembaum@.kp.org> wrote in message
news:b5cda00e.0408271644.1466e73f@.posting.google.c om...
> I am converting a database from Access to SQL Server and am trying to
> set up a relationship like the one that had been set in Access. This
> relationship had cascading deletes and updates. When I try to set up
> the relationship in SQL server, I get the message (as an example):
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
> FOREIGN KEY constraint 'FK_States-StateID' on table
> 'PersonnelInformation' may cause cycles or multiple cascade paths.
> Specify ON DELETE NO ACTION or ON
> UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
> constraint. See previous errors.
> I don't really understand why I am getting this message, unless
> cascading updates are bidirectional (meaning that a change to the
> foreign key would cascade over to the primary key:
> I basically have the following setup (I am using an example that is a
> bit easier to understand than my actual table setup:
> TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> CompanyTaxID CompanyTaxID StateID CompanyTaxID
> Company CEOName STATE SubsidiaryTaxID
> StateID AddressLine1 StateID
> ...
> StateID
> So basically I set a primary key to foreign key relationship from
> TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> and Updates).
> I also set a primary to foreign Key relationship from TABLECOMPANY
> (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> and Updates).
> Then I create a primary to foreign key relationship from TABLESTATE
> (PK) to Each of the other three tables on StateID (Update only).
> This configuration fails. I don't understand why, though clearly the
> relationships with TABLESTATE are the problem. But since TABLE state
> contains no foreign keys, nor does it specify any cascading deletes,
> no changes made anywhere could create a loop. Unless a change in a
> foreign key could affect the primary key, which doesn't make
> sense...?
> Does anyone know why this is happening. Is there a solution, or do I
> HAVE to use triggers?
> Thanks,
> Ryan
|||Hi Dejan,
Thanks. Just to clarify, is this article saying that SQL server
determines whether a key will might cause cycles or multiple cascade
paths based simply on the table in its entirety, as opposed to whether
the actual fields you will be updating could possibly cause such an
event?
In the example given, I can understand the problem, in that the setup
has two cascading updates to the same field on the many side of the
relationship. This is not the case in my example. There are not
multiple paths at the field level. A change to a state ID (in
TABLESTATE) should cause an update in the three tables it is related
to. Those tables have relationships with each other that do not
include the table TABLESTATE.
Again, though, from the TABLE level I could see how SQL might flag it.
Am I correct in what I am getting from this?
If so, this seems too bad since I think it would be easier to manage
if I could save triggers for things relationships can't do. Strange
that Access can establish the necessary relationships and SQL can't.
Oh well!
Thanks!
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si > wrote in message news:<uak74uZjEHA.704@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> Check the article at
> http://support.microsoft.com/default...;en-us;321843, it is about
> this error.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> Solid Quality Learning
> More than just Training
> www.SolidQualityLearning.com
> "Ryan" <ryan.d.rembaum@.kp.org> wrote in message
> news:b5cda00e.0408271644.1466e73f@.posting.google.c om...
set up a relationship like the one that had been set in Access. This
relationship had cascading deletes and updates. When I try to set up
the relationship in SQL server, I get the message (as an example):
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
FOREIGN KEY constraint 'FK_States-StateID' on table
'PersonnelInformation' may cause cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
I don't really understand why I am getting this message, unless
cascading updates are bidirectional (meaning that a change to the
foreign key would cascade over to the primary key:
I basically have the following setup (I am using an example that is a
bit easier to understand than my actual table setup:
TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
CompanyTaxID CompanyTaxID StateID CompanyTaxID
Company CEOName STATE SubsidiaryTaxID
StateID AddressLine1 StateID
...
StateID
So basically I set a primary key to foreign key relationship from
TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
and Updates).
I also set a primary to foreign Key relationship from TABLECOMPANY
(PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
and Updates).
Then I create a primary to foreign key relationship from TABLESTATE
(PK) to Each of the other three tables on StateID (Update only).
This configuration fails. I don't understand why, though clearly the
relationships with TABLESTATE are the problem. But since TABLE state
contains no foreign keys, nor does it specify any cascading deletes,
no changes made anywhere could create a loop. Unless a change in a
foreign key could affect the primary key, which doesn't make
sense...?
Does anyone know why this is happening. Is there a solution, or do I
HAVE to use triggers?
Thanks,
Ryan
Check the article at
http://support.microsoft.com/default...;en-us;321843, it is about
this error.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Ryan" <ryan.d.rembaum@.kp.org> wrote in message
news:b5cda00e.0408271644.1466e73f@.posting.google.c om...
> I am converting a database from Access to SQL Server and am trying to
> set up a relationship like the one that had been set in Access. This
> relationship had cascading deletes and updates. When I try to set up
> the relationship in SQL server, I get the message (as an example):
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
> FOREIGN KEY constraint 'FK_States-StateID' on table
> 'PersonnelInformation' may cause cycles or multiple cascade paths.
> Specify ON DELETE NO ACTION or ON
> UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
> constraint. See previous errors.
> I don't really understand why I am getting this message, unless
> cascading updates are bidirectional (meaning that a change to the
> foreign key would cascade over to the primary key:
> I basically have the following setup (I am using an example that is a
> bit easier to understand than my actual table setup:
> TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> CompanyTaxID CompanyTaxID StateID CompanyTaxID
> Company CEOName STATE SubsidiaryTaxID
> StateID AddressLine1 StateID
> ...
> StateID
> So basically I set a primary key to foreign key relationship from
> TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> and Updates).
> I also set a primary to foreign Key relationship from TABLECOMPANY
> (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> and Updates).
> Then I create a primary to foreign key relationship from TABLESTATE
> (PK) to Each of the other three tables on StateID (Update only).
> This configuration fails. I don't understand why, though clearly the
> relationships with TABLESTATE are the problem. But since TABLE state
> contains no foreign keys, nor does it specify any cascading deletes,
> no changes made anywhere could create a loop. Unless a change in a
> foreign key could affect the primary key, which doesn't make
> sense...?
> Does anyone know why this is happening. Is there a solution, or do I
> HAVE to use triggers?
> Thanks,
> Ryan
|||Hi Dejan,
Thanks. Just to clarify, is this article saying that SQL server
determines whether a key will might cause cycles or multiple cascade
paths based simply on the table in its entirety, as opposed to whether
the actual fields you will be updating could possibly cause such an
event?
In the example given, I can understand the problem, in that the setup
has two cascading updates to the same field on the many side of the
relationship. This is not the case in my example. There are not
multiple paths at the field level. A change to a state ID (in
TABLESTATE) should cause an update in the three tables it is related
to. Those tables have relationships with each other that do not
include the table TABLESTATE.
Again, though, from the TABLE level I could see how SQL might flag it.
Am I correct in what I am getting from this?
If so, this seems too bad since I think it would be easier to manage
if I could save triggers for things relationships can't do. Strange
that Access can establish the necessary relationships and SQL can't.
Oh well!
Thanks!
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si > wrote in message news:<uak74uZjEHA.704@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> Check the article at
> http://support.microsoft.com/default...;en-us;321843, it is about
> this error.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> Solid Quality Learning
> More than just Training
> www.SolidQualityLearning.com
> "Ryan" <ryan.d.rembaum@.kp.org> wrote in message
> news:b5cda00e.0408271644.1466e73f@.posting.google.c om...
Labels:
access,
cascading,
converting,
database,
microsoft,
mysql,
oracle,
relationship,
server,
sql,
thisrelationship,
toset
Cascading Changes in SQL Server
I am converting a database from Access to SQL Server and am trying to
set up a relationship like the one that had been set in Access. This
relationship had cascading deletes and updates. When I try to set up
the relationship in SQL server, I get the message (as an example):
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
FOREIGN KEY constraint 'FK_States-StateID' on table
'PersonnelInformation' may cause cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
I don't really understand why I am getting this message, unless
cascading updates are bidirectional (meaning that a change to the
foreign key would cascade over to the primary key:
I basically have the following setup (I am using an example that is a
bit easier to understand than my actual table setup:
TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
CompanyTaxID CompanyTaxID StateID CompanyTaxID
Company CEOName STATE SubsidiaryTaxID
StateID AddressLine1 StateID
...
StateID
So basically I set a primary key to foreign key relationship from
TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
and Updates).
I also set a primary to foreign Key relationship from TABLECOMPANY
(PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
and Updates).
Then I create a primary to foreign key relationship from TABLESTATE
(PK) to Each of the other three tables on StateID (Update only).
This configuration fails. I don't understand why, though clearly the
relationships with TABLESTATE are the problem. But since TABLE state
contains no foreign keys, nor does it specify any cascading deletes,
no changes made anywhere could create a loop. Unless a change in a
foreign key could affect the primary key, which doesn't make
sense...'
Does anyone know why this is happening. Is there a solution, or do I
HAVE to use triggers?
Thanks,
RyanCheck the article at
http://support.microsoft.com/default.aspx?scid=kb;en-us;321843, it is about
this error.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Ryan" <ryan.d.rembaum@.kp.org> wrote in message
news:b5cda00e.0408271644.1466e73f@.posting.google.com...
> I am converting a database from Access to SQL Server and am trying to
> set up a relationship like the one that had been set in Access. This
> relationship had cascading deletes and updates. When I try to set up
> the relationship in SQL server, I get the message (as an example):
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
> FOREIGN KEY constraint 'FK_States-StateID' on table
> 'PersonnelInformation' may cause cycles or multiple cascade paths.
> Specify ON DELETE NO ACTION or ON
> UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
> constraint. See previous errors.
> I don't really understand why I am getting this message, unless
> cascading updates are bidirectional (meaning that a change to the
> foreign key would cascade over to the primary key:
> I basically have the following setup (I am using an example that is a
> bit easier to understand than my actual table setup:
> TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> CompanyTaxID CompanyTaxID StateID CompanyTaxID
> Company CEOName STATE SubsidiaryTaxID
> StateID AddressLine1 StateID
> ...
> StateID
> So basically I set a primary key to foreign key relationship from
> TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> and Updates).
> I also set a primary to foreign Key relationship from TABLECOMPANY
> (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> and Updates).
> Then I create a primary to foreign key relationship from TABLESTATE
> (PK) to Each of the other three tables on StateID (Update only).
> This configuration fails. I don't understand why, though clearly the
> relationships with TABLESTATE are the problem. But since TABLE state
> contains no foreign keys, nor does it specify any cascading deletes,
> no changes made anywhere could create a loop. Unless a change in a
> foreign key could affect the primary key, which doesn't make
> sense...'
> Does anyone know why this is happening. Is there a solution, or do I
> HAVE to use triggers?
> Thanks,
> Ryan|||Hi Dejan,
Thanks. Just to clarify, is this article saying that SQL server
determines whether a key will might cause cycles or multiple cascade
paths based simply on the table in its entirety, as opposed to whether
the actual fields you will be updating could possibly cause such an
event?
In the example given, I can understand the problem, in that the setup
has two cascading updates to the same field on the many side of the
relationship. This is not the case in my example. There are not
multiple paths at the field level. A change to a state ID (in
TABLESTATE) should cause an update in the three tables it is related
to. Those tables have relationships with each other that do not
include the table TABLESTATE.
Again, though, from the TABLE level I could see how SQL might flag it.
Am I correct in what I am getting from this?
If so, this seems too bad since I think it would be easier to manage
if I could save triggers for things relationships can't do. Strange
that Access can establish the necessary relationships and SQL can't.
Oh well!
Thanks!
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in message news:<uak74uZjEHA.704@.TK2MSFTNGP09.phx.gbl>...
> Check the article at
> http://support.microsoft.com/default.aspx?scid=kb;en-us;321843, it is about
> this error.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> Solid Quality Learning
> More than just Training
> www.SolidQualityLearning.com
> "Ryan" <ryan.d.rembaum@.kp.org> wrote in message
> news:b5cda00e.0408271644.1466e73f@.posting.google.com...
> > I am converting a database from Access to SQL Server and am trying to
> > set up a relationship like the one that had been set in Access. This
> > relationship had cascading deletes and updates. When I try to set up
> > the relationship in SQL server, I get the message (as an example):
> >
> > ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
> > FOREIGN KEY constraint 'FK_States-StateID' on table
> > 'PersonnelInformation' may cause cycles or multiple cascade paths.
> > Specify ON DELETE NO ACTION or ON
> > UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> > [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
> > constraint. See previous errors.
> >
> > I don't really understand why I am getting this message, unless
> > cascading updates are bidirectional (meaning that a change to the
> > foreign key would cascade over to the primary key:
> >
> > I basically have the following setup (I am using an example that is a
> > bit easier to understand than my actual table setup:
> >
> > TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> > CompanyTaxID CompanyTaxID StateID CompanyTaxID
> > Company CEOName STATE SubsidiaryTaxID
> > StateID AddressLine1 StateID
> > ...
> > StateID
> >
> > So basically I set a primary key to foreign key relationship from
> > TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> > and Updates).
> >
> > I also set a primary to foreign Key relationship from TABLECOMPANY
> > (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> > and Updates).
> >
> > Then I create a primary to foreign key relationship from TABLESTATE
> > (PK) to Each of the other three tables on StateID (Update only).
> >
> > This configuration fails. I don't understand why, though clearly the
> > relationships with TABLESTATE are the problem. But since TABLE state
> > contains no foreign keys, nor does it specify any cascading deletes,
> > no changes made anywhere could create a loop. Unless a change in a
> > foreign key could affect the primary key, which doesn't make
> > sense...'
> >
> > Does anyone know why this is happening. Is there a solution, or do I
> > HAVE to use triggers?
> >
> > Thanks,
> > Ryan
set up a relationship like the one that had been set in Access. This
relationship had cascading deletes and updates. When I try to set up
the relationship in SQL server, I get the message (as an example):
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
FOREIGN KEY constraint 'FK_States-StateID' on table
'PersonnelInformation' may cause cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
I don't really understand why I am getting this message, unless
cascading updates are bidirectional (meaning that a change to the
foreign key would cascade over to the primary key:
I basically have the following setup (I am using an example that is a
bit easier to understand than my actual table setup:
TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
CompanyTaxID CompanyTaxID StateID CompanyTaxID
Company CEOName STATE SubsidiaryTaxID
StateID AddressLine1 StateID
...
StateID
So basically I set a primary key to foreign key relationship from
TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
and Updates).
I also set a primary to foreign Key relationship from TABLECOMPANY
(PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
and Updates).
Then I create a primary to foreign key relationship from TABLESTATE
(PK) to Each of the other three tables on StateID (Update only).
This configuration fails. I don't understand why, though clearly the
relationships with TABLESTATE are the problem. But since TABLE state
contains no foreign keys, nor does it specify any cascading deletes,
no changes made anywhere could create a loop. Unless a change in a
foreign key could affect the primary key, which doesn't make
sense...'
Does anyone know why this is happening. Is there a solution, or do I
HAVE to use triggers?
Thanks,
RyanCheck the article at
http://support.microsoft.com/default.aspx?scid=kb;en-us;321843, it is about
this error.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Ryan" <ryan.d.rembaum@.kp.org> wrote in message
news:b5cda00e.0408271644.1466e73f@.posting.google.com...
> I am converting a database from Access to SQL Server and am trying to
> set up a relationship like the one that had been set in Access. This
> relationship had cascading deletes and updates. When I try to set up
> the relationship in SQL server, I get the message (as an example):
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
> FOREIGN KEY constraint 'FK_States-StateID' on table
> 'PersonnelInformation' may cause cycles or multiple cascade paths.
> Specify ON DELETE NO ACTION or ON
> UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
> constraint. See previous errors.
> I don't really understand why I am getting this message, unless
> cascading updates are bidirectional (meaning that a change to the
> foreign key would cascade over to the primary key:
> I basically have the following setup (I am using an example that is a
> bit easier to understand than my actual table setup:
> TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> CompanyTaxID CompanyTaxID StateID CompanyTaxID
> Company CEOName STATE SubsidiaryTaxID
> StateID AddressLine1 StateID
> ...
> StateID
> So basically I set a primary key to foreign key relationship from
> TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> and Updates).
> I also set a primary to foreign Key relationship from TABLECOMPANY
> (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> and Updates).
> Then I create a primary to foreign key relationship from TABLESTATE
> (PK) to Each of the other three tables on StateID (Update only).
> This configuration fails. I don't understand why, though clearly the
> relationships with TABLESTATE are the problem. But since TABLE state
> contains no foreign keys, nor does it specify any cascading deletes,
> no changes made anywhere could create a loop. Unless a change in a
> foreign key could affect the primary key, which doesn't make
> sense...'
> Does anyone know why this is happening. Is there a solution, or do I
> HAVE to use triggers?
> Thanks,
> Ryan|||Hi Dejan,
Thanks. Just to clarify, is this article saying that SQL server
determines whether a key will might cause cycles or multiple cascade
paths based simply on the table in its entirety, as opposed to whether
the actual fields you will be updating could possibly cause such an
event?
In the example given, I can understand the problem, in that the setup
has two cascading updates to the same field on the many side of the
relationship. This is not the case in my example. There are not
multiple paths at the field level. A change to a state ID (in
TABLESTATE) should cause an update in the three tables it is related
to. Those tables have relationships with each other that do not
include the table TABLESTATE.
Again, though, from the TABLE level I could see how SQL might flag it.
Am I correct in what I am getting from this?
If so, this seems too bad since I think it would be easier to manage
if I could save triggers for things relationships can't do. Strange
that Access can establish the necessary relationships and SQL can't.
Oh well!
Thanks!
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in message news:<uak74uZjEHA.704@.TK2MSFTNGP09.phx.gbl>...
> Check the article at
> http://support.microsoft.com/default.aspx?scid=kb;en-us;321843, it is about
> this error.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> Solid Quality Learning
> More than just Training
> www.SolidQualityLearning.com
> "Ryan" <ryan.d.rembaum@.kp.org> wrote in message
> news:b5cda00e.0408271644.1466e73f@.posting.google.com...
> > I am converting a database from Access to SQL Server and am trying to
> > set up a relationship like the one that had been set in Access. This
> > relationship had cascading deletes and updates. When I try to set up
> > the relationship in SQL server, I get the message (as an example):
> >
> > ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Introducing
> > FOREIGN KEY constraint 'FK_States-StateID' on table
> > 'PersonnelInformation' may cause cycles or multiple cascade paths.
> > Specify ON DELETE NO ACTION or ON
> > UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> > [Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
> > constraint. See previous errors.
> >
> > I don't really understand why I am getting this message, unless
> > cascading updates are bidirectional (meaning that a change to the
> > foreign key would cascade over to the primary key:
> >
> > I basically have the following setup (I am using an example that is a
> > bit easier to understand than my actual table setup:
> >
> > TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> > CompanyTaxID CompanyTaxID StateID CompanyTaxID
> > Company CEOName STATE SubsidiaryTaxID
> > StateID AddressLine1 StateID
> > ...
> > StateID
> >
> > So basically I set a primary key to foreign key relationship from
> > TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> > and Updates).
> >
> > I also set a primary to foreign Key relationship from TABLECOMPANY
> > (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> > and Updates).
> >
> > Then I create a primary to foreign key relationship from TABLESTATE
> > (PK) to Each of the other three tables on StateID (Update only).
> >
> > This configuration fails. I don't understand why, though clearly the
> > relationships with TABLESTATE are the problem. But since TABLE state
> > contains no foreign keys, nor does it specify any cascading deletes,
> > no changes made anywhere could create a loop. Unless a change in a
> > foreign key could affect the primary key, which doesn't make
> > sense...'
> >
> > Does anyone know why this is happening. Is there a solution, or do I
> > HAVE to use triggers?
> >
> > Thanks,
> > Ryan
Labels:
access,
cascading,
converting,
database,
microsoft,
mysql,
oracle,
relationship,
server,
sql
Cascading Changes in SQL Server
I am converting a database from Access to SQL Server and am trying to
set up a relationship like the one that had been set in Access. This
relationship had cascading deletes and updates. When I try to set up
the relationship in SQL server, I get the message (as an example):
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Intro
ducing
FOREIGN KEY constraint 'FK_States-StateID' on table
'PersonnelInformation' may cause cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
I don't really understand why I am getting this message, unless
cascading updates are bidirectional (meaning that a change to the
foreign key would cascade over to the primary key:
I basically have the following setup (I am using an example that is a
bit easier to understand than my actual table setup:
TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
CompanyTaxID CompanyTaxID StateID CompanyTaxID
Company CEOName STATE SubsidiaryTaxID
StateID AddressLine1 StateID
..
StateID
So basically I set a primary key to foreign key relationship from
TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
and Updates).
I also set a primary to foreign Key relationship from TABLECOMPANY
(PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
and Updates).
Then I create a primary to foreign key relationship from TABLESTATE
(PK) to Each of the other three tables on StateID (Update only).
This configuration fails. I don't understand why, though clearly the
relationships with TABLESTATE are the problem. But since TABLE state
contains no foreign keys, nor does it specify any cascading deletes,
no changes made anywhere could create a loop. Unless a change in a
foreign key could affect the primary key, which doesn't make
sense...'
Does anyone know why this is happening. Is there a solution, or do I
HAVE to use triggers?
Thanks,
RyanCheck the article at
http://support.microsoft.com/defaul...b;en-us;321843, it is about
this error.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Ryan" <ryan.d.rembaum@.kp.org> wrote in message
news:b5cda00e.0408271644.1466e73f@.posting.google.com...
> I am converting a database from Access to SQL Server and am trying to
> set up a relationship like the one that had been set in Access. This
> relationship had cascading deletes and updates. When I try to set up
> the relationship in SQL server, I get the message (as an example):
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Int
roducing
> FOREIGN KEY constraint 'FK_States-StateID' on table
> 'PersonnelInformation' may cause cycles or multiple cascade paths.
> Specify ON DELETE NO ACTION or ON
> UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not creat
e
> constraint. See previous errors.
> I don't really understand why I am getting this message, unless
> cascading updates are bidirectional (meaning that a change to the
> foreign key would cascade over to the primary key:
> I basically have the following setup (I am using an example that is a
> bit easier to understand than my actual table setup:
> TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> CompanyTaxID CompanyTaxID StateID CompanyTaxID
> Company CEOName STATE SubsidiaryTaxID
> StateID AddressLine1 StateID
> ...
> StateID
> So basically I set a primary key to foreign key relationship from
> TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> and Updates).
> I also set a primary to foreign Key relationship from TABLECOMPANY
> (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> and Updates).
> Then I create a primary to foreign key relationship from TABLESTATE
> (PK) to Each of the other three tables on StateID (Update only).
> This configuration fails. I don't understand why, though clearly the
> relationships with TABLESTATE are the problem. But since TABLE state
> contains no foreign keys, nor does it specify any cascading deletes,
> no changes made anywhere could create a loop. Unless a change in a
> foreign key could affect the primary key, which doesn't make
> sense...'
> Does anyone know why this is happening. Is there a solution, or do I
> HAVE to use triggers?
> Thanks,
> Ryan|||Hi Dejan,
Thanks. Just to clarify, is this article saying that SQL server
determines whether a key will might cause cycles or multiple cascade
paths based simply on the table in its entirety, as opposed to whether
the actual fields you will be updating could possibly cause such an
event?
In the example given, I can understand the problem, in that the setup
has two cascading updates to the same field on the many side of the
relationship. This is not the case in my example. There are not
multiple paths at the field level. A change to a state ID (in
TABLESTATE) should cause an update in the three tables it is related
to. Those tables have relationships with each other that do not
include the table TABLESTATE.
Again, though, from the TABLE level I could see how SQL might flag it.
Am I correct in what I am getting from this?
If so, this seems too bad since I think it would be easier to manage
if I could save triggers for things relationships can't do. Strange
that Access can establish the necessary relationships and SQL can't.
Oh well!
Thanks!
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in message news:<uak
74uZjEHA.704@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> Check the article at
> http://support.microsoft.com/defaul...b;en-us;321843, it is abou
t
> this error.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> Solid Quality Learning
> More than just Training
> www.SolidQualityLearning.com
> "Ryan" <ryan.d.rembaum@.kp.org> wrote in message
> news:b5cda00e.0408271644.1466e73f@.posting.google.com...
set up a relationship like the one that had been set in Access. This
relationship had cascading deletes and updates. When I try to set up
the relationship in SQL server, I get the message (as an example):
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Intro
ducing
FOREIGN KEY constraint 'FK_States-StateID' on table
'PersonnelInformation' may cause cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON
UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
I don't really understand why I am getting this message, unless
cascading updates are bidirectional (meaning that a change to the
foreign key would cascade over to the primary key:
I basically have the following setup (I am using an example that is a
bit easier to understand than my actual table setup:
TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
CompanyTaxID CompanyTaxID StateID CompanyTaxID
Company CEOName STATE SubsidiaryTaxID
StateID AddressLine1 StateID
..
StateID
So basically I set a primary key to foreign key relationship from
TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
and Updates).
I also set a primary to foreign Key relationship from TABLECOMPANY
(PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
and Updates).
Then I create a primary to foreign key relationship from TABLESTATE
(PK) to Each of the other three tables on StateID (Update only).
This configuration fails. I don't understand why, though clearly the
relationships with TABLESTATE are the problem. But since TABLE state
contains no foreign keys, nor does it specify any cascading deletes,
no changes made anywhere could create a loop. Unless a change in a
foreign key could affect the primary key, which doesn't make
sense...'
Does anyone know why this is happening. Is there a solution, or do I
HAVE to use triggers?
Thanks,
RyanCheck the article at
http://support.microsoft.com/defaul...b;en-us;321843, it is about
this error.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Ryan" <ryan.d.rembaum@.kp.org> wrote in message
news:b5cda00e.0408271644.1466e73f@.posting.google.com...
> I am converting a database from Access to SQL Server and am trying to
> set up a relationship like the one that had been set in Access. This
> relationship had cascading deletes and updates. When I try to set up
> the relationship in SQL server, I get the message (as an example):
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Int
roducing
> FOREIGN KEY constraint 'FK_States-StateID' on table
> 'PersonnelInformation' may cause cycles or multiple cascade paths.
> Specify ON DELETE NO ACTION or ON
> UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not creat
e
> constraint. See previous errors.
> I don't really understand why I am getting this message, unless
> cascading updates are bidirectional (meaning that a change to the
> foreign key would cascade over to the primary key:
> I basically have the following setup (I am using an example that is a
> bit easier to understand than my actual table setup:
> TABLECOMPANY TABLECEO TABLESTATE TABLESubsidiary
> CompanyTaxID CompanyTaxID StateID CompanyTaxID
> Company CEOName STATE SubsidiaryTaxID
> StateID AddressLine1 StateID
> ...
> StateID
> So basically I set a primary key to foreign key relationship from
> TABLECOMPANY (PK) To TABLECEO (FK) on CompanyTaxID (Cascade Deletes
> and Updates).
> I also set a primary to foreign Key relationship from TABLECOMPANY
> (PK) to TABLESUBSIDIARY (FK), again on CompanyTaxID (Cascade Deletes
> and Updates).
> Then I create a primary to foreign key relationship from TABLESTATE
> (PK) to Each of the other three tables on StateID (Update only).
> This configuration fails. I don't understand why, though clearly the
> relationships with TABLESTATE are the problem. But since TABLE state
> contains no foreign keys, nor does it specify any cascading deletes,
> no changes made anywhere could create a loop. Unless a change in a
> foreign key could affect the primary key, which doesn't make
> sense...'
> Does anyone know why this is happening. Is there a solution, or do I
> HAVE to use triggers?
> Thanks,
> Ryan|||Hi Dejan,
Thanks. Just to clarify, is this article saying that SQL server
determines whether a key will might cause cycles or multiple cascade
paths based simply on the table in its entirety, as opposed to whether
the actual fields you will be updating could possibly cause such an
event?
In the example given, I can understand the problem, in that the setup
has two cascading updates to the same field on the many side of the
relationship. This is not the case in my example. There are not
multiple paths at the field level. A change to a state ID (in
TABLESTATE) should cause an update in the three tables it is related
to. Those tables have relationships with each other that do not
include the table TABLESTATE.
Again, though, from the TABLE level I could see how SQL might flag it.
Am I correct in what I am getting from this?
If so, this seems too bad since I think it would be easier to manage
if I could save triggers for things relationships can't do. Strange
that Access can establish the necessary relationships and SQL can't.
Oh well!
Thanks!
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in message news:<uak
74uZjEHA.704@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> Check the article at
> http://support.microsoft.com/defaul...b;en-us;321843, it is abou
t
> this error.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> Solid Quality Learning
> More than just Training
> www.SolidQualityLearning.com
> "Ryan" <ryan.d.rembaum@.kp.org> wrote in message
> news:b5cda00e.0408271644.1466e73f@.posting.google.com...
Labels:
access,
cascading,
converting,
database,
microsoft,
mysql,
oracle,
relationship,
server,
sql,
thisrelationship,
toset
Subscribe to:
Posts (Atom)