MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL 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 Dev Shed Forums Sponsor:
  #1  
Old September 24th, 2004, 09:51 AM
lauramccord lauramccord is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 180 lauramccord User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 3 m 58 sec
Reputation Power: 5
Creating a Composite Key

Can someone help me create a composite key on ms sql server through the enterprise manager?

Thanks,
Laura

Reply With Quote
  #2  
Old September 24th, 2004, 07:06 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
would you accept a solution that you could use in query analyzer instead?
Code:
create table FOO
( id smallint not null primary key identity
, name varchar(9)
)

insert into FOO ( name ) values ( 'curly' )
insert into FOO ( name ) values ( 'larry' )
insert into FOO ( name ) values ( 'moe' )


create table BAR
( id smallint not null primary key identity
, name varchar(9)
)

set identity_insert BAR on

insert into BAR ( id, name ) values ( 101, 'dog' )
insert into BAR ( id, name ) values ( 102, 'cat' )

set identity_insert BAR off

insert into BAR ( name ) values ( 'fish' )
insert into BAR ( name ) values ( 'gerbil' )  


create table FUBAR
( FOOid smallint not null 
, BARid smallint not null 
, foreign key ( FOOid ) references FOO ( id )
, foreign key ( BARid ) references BAR ( id )
, primary key ( FOOid, BARid )
)

insert into FUBAR values ( 1, 101)
insert into FUBAR values ( 1, 102)
insert into FUBAR values ( 1, 104)
insert into FUBAR values ( 3, 102)
insert into FUBAR values ( 3, 104)


select FOO.name as Stooge
     , BAR.name as Pet
  from FOO
inner
  join FUBAR
    on FOO.id = FUBAR.FOOid
inner
  join BAR
    on FUBAR.BARid = BAR.id
order
    by Stooge
     , Pet    

RESULTS:
    
Stooge Pet 
curly  cat
curly  dog
curly  gerbil
moe    cat
moe    gerbil    
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Creating a Composite Key


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


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





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