Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 05-31-2007, 7:41 PM   #1
matt
 
matt's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default examples of INNODB & foreign keys

does anyone know of any good examples of using INNODB tables and foreign
keys to manage references to other tables. I want to manage removing
entries and teh references in other tables.

thanks!


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 05-31-2007, 7:42 PM   #2
matt
 
matt's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default examples of INNODB & foreign keys

"Steve" <Steve@127.0.0.1> wrote in message
news:jmp7r2-ebu.ln1@barnyard.sweetpig.dyndns.org...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Thu, 21 Jul 2005 23:03:51 -0400, matt in alt.comp.databases.mysql
> wrote:
>>does anyone know of any good examples of using INNODB tables and foreign
>>keys to manage references to other tables. I want to manage removing
>>entries and teh references in other tables.

>
>>thanks!

>
> create table xxxx
> (
> xxxID int not null auto_increment primary key,
> name varchar(80),
> job varchar(30),
> xxx00ID int not null references DDD(dddID)
> )
> type=InnoDB;


anybody got anything w/ an explanation?


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:42 PM   #3
matt
 
matt's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default examples of INNODB & foreign keys

"Steve" <Steve@127.0.0.1> wrote in message
news:ttt8r2-ef3.ln1@barnyard.sweetpig.dyndns.org...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Fri, 22 Jul 2005 19:27:01 -0400, matt in alt.comp.databases.mysql
> wrote:
>>"Steve" <Steve@127.0.0.1> wrote in message
>>news:jmp7r2-ebu.ln1@barnyard.sweetpig.dyndns.org...
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> On Thu, 21 Jul 2005 23:03:51 -0400, matt in alt.comp.databases.mysql
>>> wrote:
>>>>does anyone know of any good examples of using INNODB tables and foreign
>>>>keys to manage references to other tables. I want to manage removing
>>>>entries and teh references in other tables.
>>>
>>>>thanks!
>>>
>>> create table xxxx
>>> (
>>> xxxID int not null auto_increment primary key,
>>> name varchar(80),
>>> job varchar(30),
>>> xxx00ID int not null references DDD(dddID)
>>> )
>>> type=InnoDB;

>
>>anybody got anything w/ an explanation?

>
> http://dev.mysql.com/doc/mysql/en/innodb.html
> http://dev.mysql.com/doc/mysql/en/in...nstraints.html
>


maybe if i explain what i'm doing and see if i'm talking about the right
thing. I currently have a database with 4 tables. 3 tables contain
information and a id for each entry. the 4th table is a relationship table
and it connects each table. right now the reference table only has the ids
of each of the other tables in it, but they are not set up as foreign keys.
If i erase an entry from a table, when i try to lookup the data in the
reference table, it is blank. Lastly, i have to do a left join each time i
look up data. I'm looking to find out if A) i'm doing this correctly, B) if
there is a better way of doing it, C), if i can look up the data with out
doing a left join. if anyone has an example (i.e., showing the creation of
the table, the data contained, and how the data is extracted) i'd appreciate
it.

thanks,


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:42 PM   #4
JMA
 
JMA's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default examples of INNODB & foreign keys

Hi Matt,

Maybe the following sample could help you:

-- Create the 3 tables containing information
--
create table table_a (ida int not null primary key) engine=innodb;
create table table_b (idb int not null primary key) engine=innodb;
create table table_c (idc int not null primary key) engine=innodb;

-- Create a relationship table between the 3 'information' tables
--
create table relation_abc
(
ida int not null,
idb int not null,
idc int not null,
constraint pk_abc primary key (ida, idb, idc),
constraint fk_a foreign key (ida) references table_a(ida) on update no
action on delete cascade,
constraint fk_b foreign key (idb) references table_b(idb) on update no
action on delete cascade,
constraint fk_c foreign key (idc) references table_c(idc) on update no
action on delete cascade
)
engine=innodb;

-- Insert sample data
--
insert into table_a values (1);
insert into table_a values (2);
insert into table_a values (3);

insert into table_b values (10);
insert into table_b values (20);
insert into table_b values (30);

insert into table_c values (100);
insert into table_c values (200);
insert into table_c values (300);

insert into relation_abc values (1, 10, 100);
insert into relation_abc values (1, 20, 100);
insert into relation_abc values (2, 20, 200);
insert into relation_abc values (2, 20, 300);
insert into relation_abc values (3, 10, 300);
insert into relation_abc values (3, 20, 300);
insert into relation_abc values (3, 30, 300);

-- After executing the following delete clauses, the relation table is empty
--
delete from table_a where ida=1;
delete from table_b where idb=20;
delete from table_c where idc=300;

I hope this sample show you the advantages of using referential integrity...

Regards

JMA


"matt" <guest@guest.com> a écrit dans le message de news:
r6idnWy_VKqI_33fRVn-iQ@comcast.com...
> does anyone know of any good examples of using INNODB tables and foreign
> keys to manage references to other tables. I want to manage removing
> entries and teh references in other tables.
>
> thanks!
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
innodb error Paul Cupis Database 0 05-31-2007 7:41 PM
Stopping INNODB monitor Justin Database 0 05-31-2007 7:38 PM
Google - Automatic translation of foreign news? FishFood Google questions 0 05-28-2007 12:46 AM
Net_Url_Mapper examples arnaud sellenet Pear 2 05-20-2007 5:34 PM
Keys into keys in template flexy Jandro brozaman Pear 1 05-20-2007 5:34 PM


Featured Websites




All times are GMT +1. The time now is 12:57 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98