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

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 How to create the linking table

Author  Topic 

skiabox
Posting Yak Master

169 Posts

Posted - 2008-11-27 : 04:18:29
I have a many to many relationship.
The first table buildings_add_jobs has the following primary key
(buildings_add_jobs.add_job_id, buildings_add_jobs.building_id)
The second table add_jobs_schedule has the following primary key
(add_jobs_schedule.job_date, add_jobs_schedule.add_job_id)
How can I create the linking table?
Thank you very much!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-27 : 04:23:22
just use create table statement.see examples below

http://doc.ddart.net/mssql/sql70/create_7.htm
Go to Top of Page

skiabox
Posting Yak Master

169 Posts

Posted - 2008-11-27 : 04:28:52
Hello visakh16!
I know about the create table statement.
An example I am reading in a book is this one :

create table engineer
(emp_id char(10),
primary key (emp_id));

create table prof_assoc
(assoc_name varchar(256),
primary key (assoc_name));

create table belongs_to
(emp_id char(10),
assoc_name var char(256),
primary key (emp_id, assoc_name),
foreign key (emp_id) references engineer
on delete cascade on update cascade,
foreign key (assoc_name) references prof_assoc
on delete cascade on update cascade);

My problem here is that the primary keys of the tables are not a single column but they consist of two column each.
How can I code this?
Thanks again visakh16.
You have helped me many times!
:)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-27 : 05:18:50
quote:
Originally posted by skiabox

Hello visakh16!
I know about the create table statement.
An example I am reading in a book is this one :

create table engineer
(emp_id char(10),
primary key (emp_id));

create table prof_assoc
(assoc_name varchar(256),
primary key (assoc_name));

create table belongs_to
(emp_id char(10),
assoc_name var char(256),
primary key (emp_id, assoc_name),
foreign key (emp_id) references engineer
on delete cascade on update cascade,
foreign key (assoc_name) references prof_assoc
on delete cascade on update cascade);

My problem here is that the primary keys of the tables are not a single column but they consist of two column each.
How can I code this?
Thanks again visakh16.
You have helped me many times!
:)


the above code works for me. what errpr you're getting?
b/w you just had a space between var & char which complained. aprt from that everything's fine
Go to Top of Page
   

- Advertisement -