If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Unique index acrosss 2 tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-16-10, 21:49
djuritz djuritz is offline
Registered User
 
Join Date: Sep 2005
Posts: 67
Unique index acrosss 2 tables

Hi all,

I have two tables: Users and companies. Both have field EMAIL as unique

Is there any way to prevent duplicated email acrosss different tables?
The idea is to prevent a company and a user with same email address.

Currently I check it at moment of register wether the email exists on both tables, but I'd like to have something more solid.

I'm using MySQL 5, MyISAM

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 05-16-10, 22:15
scottb scottb is offline
Registered User
 
Join Date: Oct 2003
Posts: 60
You can't do that.

why not redesign your db and have a table to hold unique email addresses and created FK's from the other 2 tables.
Reply With Quote
  #3 (permalink)  
Old 05-17-10, 02:45
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Quote:
Originally Posted by scottb View Post
created FK's from the other 2 tables.
Not with MyISAM
Reply With Quote
  #4 (permalink)  
Old 05-17-10, 13:32
scottb scottb is offline
Registered User
 
Join Date: Oct 2003
Posts: 60
Red face

Quote:
Originally Posted by shammat View Post
Not with MyISAM
oooooopsie.
Reply With Quote
  #5 (permalink)  
Old 05-17-10, 20:43
Diesel Dud Diesel Dud is offline
Registered User
 
Join Date: Feb 2010
Location: Montreal, CA
Posts: 32
Using 1 table instead of 2, you can solve your problem:

TableA
-------
1- Email (PK)
2- Type: User/Company
3- ...
Reply With Quote
Reply

Tags
unique multiple tables

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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