Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
2.00/5 (1 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

Allow NULL for the foreign key column and insert NULL instead of a valid Id for the non system level calls.
 
Share this answer
 
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
[no name] 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 ?
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...
 
Share this answer
 
Searched and found that no such feaure available in sql server
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900