Showing posts with label maybesomeone. Show all posts
Showing posts with label maybesomeone. Show all posts

Friday, February 24, 2012

INSERT problem

I'm not sure if this is the right place to post this, if not, maybe
someone could give me a pointer to where to ask the question...
A friend and I are trying to figure out if it's possible to create a
table that will allow an insert of a value into column A only if that
value is already in column B or if it being inserted into column B by
that insert statement.
We've done some looking around, but haven't found an answer yet...
Sounds like you want a FOREIGN KEY constraint on a self-referencing table:
create table MyTable
(
ColA int primary key
, ColB int not null
references MyTable (ColA)
)
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Jakanapes" <Jakanapes@.aol.com> wrote in message
news:1130156166.728791.38140@.g49g2000cwa.googlegro ups.com...
I'm not sure if this is the right place to post this, if not, maybe
someone could give me a pointer to where to ask the question...
A friend and I are trying to figure out if it's possible to create a
table that will allow an insert of a value into column A only if that
value is already in column B or if it being inserted into column B by
that insert statement.
We've done some looking around, but haven't found an answer yet...
|||Yes, you can use an INSERT trigger for that, using the virtual inserted table inside your trigger
code. Or possibly a self referencing foreign key, if column B is a key of the table.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jakanapes" <Jakanapes@.aol.com> wrote in message
news:1130156166.728791.38140@.g49g2000cwa.googlegro ups.com...
> I'm not sure if this is the right place to post this, if not, maybe
> someone could give me a pointer to where to ask the question...
> A friend and I are trying to figure out if it's possible to create a
> table that will allow an insert of a value into column A only if that
> value is already in column B or if it being inserted into column B by
> that insert statement.
> We've done some looking around, but haven't found an answer yet...
>

INSERT problem

I'm not sure if this is the right place to post this, if not, maybe
someone could give me a pointer to where to ask the question...
A friend and I are trying to figure out if it's possible to create a
table that will allow an insert of a value into column A only if that
value is already in column B or if it being inserted into column B by
that insert statement.
We've done some looking around, but haven't found an answer yet...Sounds like you want a FOREIGN KEY constraint on a self-referencing table:
create table MyTable
(
ColA int primary key
, ColB int not null
references MyTable (ColA)
)
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Jakanapes" <Jakanapes@.aol.com> wrote in message
news:1130156166.728791.38140@.g49g2000cwa.googlegroups.com...
I'm not sure if this is the right place to post this, if not, maybe
someone could give me a pointer to where to ask the question...
A friend and I are trying to figure out if it's possible to create a
table that will allow an insert of a value into column A only if that
value is already in column B or if it being inserted into column B by
that insert statement.
We've done some looking around, but haven't found an answer yet...|||Yes, you can use an INSERT trigger for that, using the virtual inserted tabl
e inside your trigger
code. Or possibly a self referencing foreign key, if column B is a key of th
e table.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jakanapes" <Jakanapes@.aol.com> wrote in message
news:1130156166.728791.38140@.g49g2000cwa.googlegroups.com...
> I'm not sure if this is the right place to post this, if not, maybe
> someone could give me a pointer to where to ask the question...
> A friend and I are trying to figure out if it's possible to create a
> table that will allow an insert of a value into column A only if that
> value is already in column B or if it being inserted into column B by
> that insert statement.
> We've done some looking around, but haven't found an answer yet...
>