Click here to Skip to main content
14,271,804 members
Rate this:
Please Sign up or sign in to vote.
Hi all,
I have two table
One table is Systemcode (ID Uniqueindetifier , name NVARCHAR(50))
Second table is calldesk (type NVARCHAR(50),systemid Uniqueindetifier)

Now there may a system level call or non system level call.
when there is system level call i have to insert one record in calldesk with proper system id (present in systemcode)

and when there is non system level call i have to insert one record in calldesk with empty system id (0000-0000......)

Now to validate the first level i need to create FK between systemid form calldesk to id from systemid with check condition of second level because there is not such record in systemid table with empty id (0000-000....)

Also i can not insert the empty id systemid table.

also i can not check this from SP . because there is already 500 SP which will insert the data into call desk from same level.


can i achieve this with check constraint. ?
Posted
Comments
Sunasara Imdadhusen 1-Dec-10 8:24am
   
Good question
Rate this:
Please Sign up or sign in to vote.

Solution 1

Allow NULL for the foreign key column and insert NULL instead of a valid Id for the non system level calls.
   
Comments
RDBurmon 1-Dec-10 8:51am
   
No CDP1802 , I can not do this , cause insertion may be occured from 500 SP and they mean empty systemid means (0000-000...) there is no concept of null.
also i can not allow null from table level cause it hang up other process which may be call from another 500 SPs
CDP1802 1-Dec-10 9:44am
   
In that case this is a dead end. This is no good database design and foreign key checking will not be possible.
RDBurmon 2-Dec-10 4:20am
   
Yeap CDP1802 , I agree with you . but i am asking about another way othere that FK. like if we want to constraint on value enter in column let suppose age . then i can achieve this by providing check constraint such as value > 0 and value <= 100. is there any kind of way to achieve these ?
Rate this:
Please Sign up or sign in to vote.

Solution 2

hello, i have similiar problem... i have a more than one table that need to be addressed in single foreign key, base on even odds... or x mod y type
for example if table_referenced has x then
if x mod 3 = 0
then load records from table1
if x mod 3 = 1
then load records from table2
if x mod 3 = 2
then load records from table3


but like in this way
create table table_referenced
(
ref_field int references table1(t1id),table2(t2id),table3(t3id)
)

i know there is no such command but i want something that do the same thing...
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Searched and found that no such feaure available in sql server
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100