Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Referential Integrity and Constraint Question

Posted on 2010-01-07
2
Medium Priority
?
360 Views
Last Modified: 2012-05-08
Hi,

I have two tables, "Customer" and "Inactive"

Customer Table

cust_id (PK)       cust_name          status
1                 ABC Company    0
4                 XYG Company    2

Status Table

status(PK)       status_desc
0                   some desc
1                  diff desc
2                  2nd desc

I want to create a constraint between the PK of the Status table and the Status column in the Customer table.   What would be the SQL needed to do this?

I basically want to prevent a user from creating a record in the Customer Table with a value in the status column that doesn't exist in the Status table.

Hope that makes sense.

-ws
0
Comment
Question by:Westside2004
2 Comments
 
LVL 12

Accepted Solution

by:
HugoHiasl earned 2000 total points
ID: 26197935
ALTER TABLE Customer ADD FOREIGN KEY (status) REFERENCES Status(status)

0
 
LVL 1

Author Closing Comment

by:Westside2004
ID: 31673911
Thanks
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question