SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Enforcing constraints plssss helpp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Tiara
Starting Member

6 Posts

Posted - 04/26/2012 :  23:15:00  Show Profile  Reply with Quote
Hi There,
I have a question regarding enforce a constraint to my table.
There are works on table and a staff table, each staff has specific title(supervisor,authorizer,manager,...). I need to ensure that the supervisor and the authorizer cannot be the same staff on workson table. I am not sure how to do it.
Can you please advise me to solve this problem?

Thanks

Edited by - Tiara on 04/27/2012 00:44:57

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 04/26/2012 :  23:25:28  Show Profile  Reply with Quote

alter table <table name> add constraint <constraint name> check ( supervisor <> authorizer )



KH
Time is always against us

Go to Top of Page

Tiara
Starting Member

6 Posts

Posted - 04/26/2012 :  23:36:19  Show Profile  Reply with Quote
Thanks for the respond but I don't think is possible to do that because the relationship between these two tables is many to many. I need to enforce constraint to the third table which is workson_staff however I don't have staff title on that table. So how can I use this statement in this case?
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 04/27/2012 :  00:33:51  Show Profile  Reply with Quote
oh 2 tables ? maybe you can post the table schema, it will help us to understand the situation better


KH
Time is always against us

Go to Top of Page

Tiara
Starting Member

6 Posts

Posted - 04/27/2012 :  00:54:33  Show Profile  Reply with Quote
how can i send an image to the forum?
Go to Top of Page

Tiara
Starting Member

6 Posts

Posted - 04/27/2012 :  02:10:35  Show Profile  Reply with Quote
Here is my table schema http://sqlhelp1.blogspot.com.au/
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 04/27/2012 :  02:25:13  Show Profile  Reply with Quote
by the looks of it, you probably have to enforce this in your application


KH
Time is always against us

Go to Top of Page

vinu.vijayan
Posting Yak Master

India
227 Posts

Posted - 04/27/2012 :  03:16:59  Show Profile  Reply with Quote
quote:
Originally posted by Tiara

Here is my table schema http://sqlhelp1.blogspot.com.au/



From the above link...I understand that the difference in StaffTyp ie: admin or supervisor is coming because the field "StaffType" in the table "WorksOnStaff" is not an FK referencing the field "StaffType" in the table "Staff".
The constraint you need to add here is on the field "StaffType" in the table "WorksOnStaff" by making it a Foreign Key that references the field "StaffType" in the table "Staff".

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

Tiara
Starting Member

6 Posts

Posted - 04/27/2012 :  03:29:11  Show Profile  Reply with Quote
What if, other roles are able to be assigned to more than one particular assignment? For example Mary green can be a supervisor and a sales person of the particular assignment but she cannot be the authorizer for particular assignment?
Go to Top of Page

vinu.vijayan
Posting Yak Master

India
227 Posts

Posted - 04/27/2012 :  05:02:15  Show Profile  Reply with Quote
So, you are saying that every Staff in the "Staff" table has a "StaffType" but when some Work is carried out then the Staff can be assigned some other "StaffType" in the "WorkStaff" table??

Is that what you mean?

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 04/27/2012 :  06:54:45  Show Profile  Visit robvolk's Homepage  Reply with Quote
FYI SQLTeam is a Microsoft SQL Server website, and your ERD looks like it's an Oracle database. You'll get better responses to Oracle questions over at http://dbforums.com/.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000