SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 13th, 2008, 09:29 AM
asptips asptips is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: asian
Posts: 385 asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 52 m 27 sec
Reputation Power: 16
Create Relationship between Tables

Hello,

How do I create a script that have a relationship between two tables from the two tables I successfully created below.

Dim addTable1 As String = "CREATE TABLE t1(idT1 int IDENTITY(1,1) PRIMARY KEY, tField1 nvarchar(50))"
Dim addTable2 As String = "CREATE TABLE t2(idT2 int IDENTITY(1,1) PRIMARY KEY, tField2 nvarchar(50), idT1 int)"

A relationship between idT1 in t1 table and idT1 in t2 table.


cheers,
asptips

Reply With Quote
  #2  
Old April 14th, 2008, 06:36 AM
jmurrayhead's Avatar
jmurrayhead jmurrayhead is offline
The Drunken Moderator
Click here for more information.
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 12,944 jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 76972 Folding Title: Intermediate FolderFolding Points: 76972 Folding Title: Intermediate FolderFolding Points: 76972 Folding Title: Intermediate FolderFolding Points: 76972 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 2 Days 21 h 31 m 12 sec
Reputation Power: 1456
Facebook
__________________
jmurrayhead

Did I help you out? Make me popular by clicking the icon!

New Members:Proper way to post a question

Powered by ASP.Net

Reply With Quote
  #3  
Old April 16th, 2008, 01:35 AM
asptips asptips is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: asian
Posts: 385 asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level)asptips User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 52 m 27 sec
Reputation Power: 16
Quote:
Originally Posted by jmurrayhead


What if the table already exist? I receive this error "Incorrect syntax near '('."

Dim addTable1 As String = "CREATE TABLE t1(idT1 int IDENTITY(1,1) PRIMARY KEY, tField1 nvarchar(50))"
Dim addTable2 As String = "CREATE TABLE t2(idT2 int IDENTITY(1,1) PRIMARY KEY, tField2 nvarchar(50), idT1 int)"

Dim relateTable As String = "ALTER TABLE t2(FOREIGN KEY idT1 TAG idT1 REFERENCES t1)"


Is my syntax correct?


cheers,
asptips

Reply With Quote
  #4  
Old April 16th, 2008, 06:35 AM
jmurrayhead's Avatar
jmurrayhead jmurrayhead is offline
The Drunken Moderator
Click here for more information.
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 12,944 jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 76972 Folding Title: Intermediate FolderFolding Points: 76972 Folding Title: Intermediate FolderFolding Points: 76972 Folding Title: Intermediate FolderFolding Points: 76972 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 2 Days 21 h 31 m 12 sec
Reputation Power: 1456
Facebook
Here's an example:

Code:
ALTER TABLE ORDERS 
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
Comments on this post
asptips agrees: Thanks!!!

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Create Relationship between Tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway