gaza165 Posted April 16, 2010 Share Posted April 16, 2010 Hi Everyone, I have a table structure as follows: Store_ID | Employee_ID ------------------------------------------- 1 | 2 1 | 2 <<<<<<<<<< cant have this!! 2 | 2 <<<<<<<<<< can have this!! Basically, one of the criterias is that I cant have the same employee as part of the same store... So i guess what im trying to achieve is that duplicate records cant appear in the table. Can anyone offer any advice on how to enforce this in my table structure?? Thanks Garry Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/ Share on other sites More sharing options...
Jax2 Posted April 16, 2010 Share Posted April 16, 2010 Do a query and see if that already exists in the database and if it does, pop up a message saying Cannot add, duplicate and if not, go ahead and add it with another query ... Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/#findComment-1042954 Share on other sites More sharing options...
gaza165 Posted April 16, 2010 Author Share Posted April 16, 2010 Is there no way in SQL on creating the table I can set something when i create the table to not allow duplicate values? Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/#findComment-1042957 Share on other sites More sharing options...
xX_SuperCrazy_Xx Posted April 16, 2010 Share Posted April 16, 2010 Hi there, In addition to the suggsted solution by gaza165, you need to make both Store_ID and Employee_ID as the primary key of the table. This will enfource that no duplicate can happen and even when you have no check the system will through an error messge. Regards Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/#findComment-1042960 Share on other sites More sharing options...
Jax2 Posted April 16, 2010 Share Posted April 16, 2010 Well sure, you can set the field to unique, as in, no other record can have the same value, but then if you try and insert it, you're going to get a broken query, so you'll still have to do the query check first anyhow... Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/#findComment-1042961 Share on other sites More sharing options...
gaza165 Posted April 16, 2010 Author Share Posted April 16, 2010 Hi Guys, Im keeping this context out of PHP...just concentrating on SQL. What you have suggested is brilliant, the whole idea of this question is that I create a suitable database schema for the operations to be performed on the tables. So, you are saying...if I set both ID's as primary keys i wont be able to have duplicate values in my table??? Garry Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/#findComment-1042962 Share on other sites More sharing options...
xX_SuperCrazy_Xx Posted April 16, 2010 Share Posted April 16, 2010 The answer to your question is "Yes" Quote Link to comment https://forums.phpfreaks.com/topic/198734-not-allowing-duplicate-records-in-table/#findComment-1042963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.