Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Relationship within tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

morietrenatus
Starting Member

Dominican Republic
2 Posts

Posted - 04/21/2013 :  22:42:57  Show Profile  Reply with Quote
Can anyone help me teaching me the code to make a relationship between two tables and explain me the meaning of each command.

MuMu88
Aged Yak Warrior

549 Posts

Posted - 04/21/2013 :  23:04:15  Show Profile  Reply with Quote
You can start here:
http://en.wikipedia.org/wiki/Relational_Database
http://en.wikipedia.org/wiki/SQL
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/22/2013 :  00:44:37  Show Profile  Reply with Quote
the relation ship between two tables is defined by means of foreign key relationship
see this illustration

CREATE TABLE Products
(
ProductID int NOT NULL PRIMARY KEY,
ProductName varchar(100)
)

CREATE TABLE Orders
(
OrderID int NOT NULL PRIMARY KEY,
ProductID int NOT NULL,
Qty int,
Price money
)

ALTER TABLE Orders
ADD CONSTRAINT fk_PerOrders
FOREIGN KEY (ProductID)
REFERENCES Product(ProductID)



the above code will create a relationship between Orders and Products

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next 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.03 seconds. Powered By: Snitz Forums 2000