Click here to Skip to main content
15,883,705 members
Home / Discussions / Database
   

Database

 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel15-Jul-11 2:22
professionalShameel15-Jul-11 2:22 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
AnnieMacD15-Jul-11 2:45
AnnieMacD15-Jul-11 2:45 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel15-Jul-11 7:50
professionalShameel15-Jul-11 7:50 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
AnnieMacD15-Jul-11 7:56
AnnieMacD15-Jul-11 7:56 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
smcnulty200015-Jul-11 5:39
smcnulty200015-Jul-11 5:39 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel15-Jul-11 7:48
professionalShameel15-Jul-11 7:48 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
smcnulty200015-Jul-11 8:08
smcnulty200015-Jul-11 8:08 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
AnnieMacD15-Jul-11 2:44
AnnieMacD15-Jul-11 2:44 
The Primary Key for the linking table is a composite of InstructorID + CourseID (in my example). This then makes it unique which a Primary Key has to be. There is NO other data in the linking table.

This then effectively creates a many-to-many relationship.

Here are the commands for creating the linking table assuming you have a Course table with Primary Key CourseID and an Instructor table with Primary Key InstructorID.

CREATE TABLE [dbo].[CourseInstructor](
	[CourseID] [int] NOT NULL,
	[InstructorID] [int] NOT NULL,
 CONSTRAINT [PK_CourseInstructor] PRIMARY KEY CLUSTERED 
(
	[CourseID] ASC,
	[InstructorID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[CourseInstructor]  WITH CHECK ADD  CONSTRAINT [FK_CourseInstructor_Course] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Course] ([CourseID])
GO

ALTER TABLE [dbo].[CourseInstructor] CHECK CONSTRAINT [FK_CourseInstructor_Course]
GO

ALTER TABLE [dbo].[CourseInstructor]  WITH CHECK ADD  CONSTRAINT [FK_CourseInstructor_Instructor] FOREIGN KEY([InstructorID])
REFERENCES [dbo].[Instructor] ([InstructorID])
GO

ALTER TABLE [dbo].[CourseInstructor] CHECK CONSTRAINT [FK_CourseInstructor_Instructor]
GO

It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
smcnulty200014-Jul-11 23:20
smcnulty200014-Jul-11 23:20 
QuestionTemp and variable table cannot be created. Pin
Groulien10-Jul-11 22:27
Groulien10-Jul-11 22:27 
AnswerRe: Temp and variable table cannot be created. Pin
Shameel11-Jul-11 1:42
professionalShameel11-Jul-11 1:42 
AnswerRe: Temp and variable table cannot be created. Pin
DaveAuld11-Jul-11 2:57
professionalDaveAuld11-Jul-11 2:57 
AnswerRe: Temp and variable table cannot be created. Pin
Corporal Agarn11-Jul-11 6:00
professionalCorporal Agarn11-Jul-11 6:00 
AnswerRe: Temp and variable table cannot be created. Pin
S Douglas11-Aug-11 10:07
professionalS Douglas11-Aug-11 10:07 
QuestionRestoration of publisher database to another system (merge replication) Pin
Abd.Jabbar9-Jul-11 21:39
Abd.Jabbar9-Jul-11 21:39 
AnswerRe: Restoration of publisher database to another system (merge replication) Pin
Corporal Agarn11-Jul-11 3:28
professionalCorporal Agarn11-Jul-11 3:28 
QuestionWho owns the data/database? Customer or vendor? Pin
kmoorevs9-Jul-11 5:55
kmoorevs9-Jul-11 5:55 
AnswerRe: Who owns the data/database? Customer or vendor? Pin
Mycroft Holmes9-Jul-11 13:13
professionalMycroft Holmes9-Jul-11 13:13 
AnswerRe: Who owns the data/database? Customer or vendor? Pin
PIEBALDconsult10-Jul-11 6:32
mvePIEBALDconsult10-Jul-11 6:32 
GeneralRe: Who owns the data/database? Customer or vendor? Pin
kmoorevs11-Jul-11 9:14
kmoorevs11-Jul-11 9:14 
AnswerRe: Who owns the data/database? Customer or vendor? Pin
jschell12-Jul-11 11:08
jschell12-Jul-11 11:08 
GeneralRe: Who owns the data/database? Customer or vendor? Pin
kmoorevs13-Jul-11 5:03
kmoorevs13-Jul-11 5:03 
GeneralRe: Who owns the data/database? Customer or vendor? Pin
jschell13-Jul-11 9:05
jschell13-Jul-11 9:05 
GeneralRe: Who owns the data/database? Customer or vendor? Pin
smcnulty200014-Jul-11 23:04
smcnulty200014-Jul-11 23:04 
AnswerRe: Who owns the data/database? Customer or vendor? Pin
smcnulty200014-Jul-11 23:01
smcnulty200014-Jul-11 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.