Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
creating associative entities?
Old 11-21-2005, 04:29 PM creating associative entities?
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
Ok i have this DB i'm creating and I'm not sure how you would create the associative entity from the ERD, or if you even create it at all?

here's the normalized tables.

organization| orgid, orgname, orgstreet, orgstate, orgcity, orgstate, orgzip, chanid (foreign)

channel | chanid, chantitle, chancontent

function | funid, date, time, name

location | lid, street, city, state, zip

details | date, orgid, funid, lid

The details table is the one i'm having a problem with. when i try to upload the text file to MySql server i get an error message saying that i can only have on eprimary key . So how would i create this without actually making the table with all the keys? or do i even need to create it do i just join them?

also for some reason if i use FOREIGN KEY when creating tables MySql kicks it back with an error

here's the table creation code
Code:
CREATE TABLE organization(
  orgId int(6) not null primary key auto_increment,
   orgName VARCHAR(20),
   orgStreet VARCHAR(20),
   orgCity VARCHAR(10),
   orgState VARCHAR(40),
   orgZip int (9),
   chanId VARCHAR(100) 
);
CREATE TABLE channel(
	chanId int(6) not null primary key auto_increment,
	chanTitle VARCHAR (20),
	chanContent VARCHAR(1000)
);
CREATE TABLE function(
	funId int(6) not null primary key auto_increment,
	date date,
	time int(4), 
	name VARCHAR(20)
);
CREATE TABLE location(
	lId int(6) not null primary key auto_increment,
	street VARCHAR(20),
	city VARCHAR(20),
	state VARCHAR(20),
	zip int(9)
);
CREATE TABLE details(
	date date not null primary key,
	orgId int(6) not null primary key,
	funid int(6) not null primary key,
	lId int(6) not null
);
The_Anomaly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-21-2005, 06:20 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
To use FOREIGN KEY you'll need to make your tables in to InnoDB tables. MySQL creates MyISAM tables by default I think. You don't really need to enforce this relationship, although it is possible to have a chanid in the org table that doesn't point to an actual channel.

You can indeed only have one primary key. I would recommend having an ID column on the details table, call it just ID or detID or whatever. Then have all the others as foreign keys (if you change your tables) or just leave them as standard fields.

There are mySQL docs on changing from MyISAM to InnoDB here: http://dev.mysql.com/doc/refman/5.0/...to-innodb.html
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 11-21-2005, 07:05 PM
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
If what your saying is true and would work efficiently, why when normalizing to 3NF or making an Associative entity in the ERD do you have more than one primary key?
The_Anomaly is offline
Reply With Quote
View Public Profile
 
Old 11-22-2005, 04:09 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
It's a year or so since I looked at Entity Relationship Diagrams...

I googled a bit for this, and found that you can specify multiple fields as a primary key, although it requires slightly different syntax:

Code:
CREATE TABLE details(
	date date not null,
	orgId int(6) not null,
	funid int(6) not null,
	lId int(6) not null,
        PRIMARY KEY (`date`, orgId, funid, lId) 
);
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to creating associative entities?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13583 seconds with 12 queries