473,657 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Multi Column Primary Key Problems

Hi

I am having trouble with ms-access and trying to determind whether or
not a row already exisitng in a particular table.

I have 3 tables namly Projects, ProjectsAttence dByContact,
ContactDetails
Defined as below.

Projects ProjectsAttende dByContact ContactDetails
------------ -------------------------- ------------------
*ProjectID *ProjectID *RefrenceNumber
ProjectName *RefrenceNumber Name
ThisProjectYes/No AttendedYes/No Surname
etc. etc.

What I am trying to do is allow a contact to attend many projects.

I have a form which has the Refrence number on it. So when I move to
the next record on the form I'd like to check if the combination of
ProjectID and RefrenceNumber exists in the ProjectsAttende dByContact
table - and if not to insert this combination into the table.

(I should have noted that the field onthe Projects table called
ThisProjectYes/No denotes which onthe list of projects we are currently
dealing with)

The SQL that I have been working on looks like this::
SELECT 5 AS Expr1, Projects.Projec tID AS Projects_Projec tID,
Projects.Projec tName, Projects.ThisPr oject
FROM Projects
WHERE (((5) Not In (select RefrenceNumber from
ProjectsAttende dByContact)) AND ((Projects.Proj ectID)<>Exists (select
ProjectID from ProjectsAttende dByContact)) AND
((Projects.This Project)=Yes));

WHERE 5 would be the RefrenceNumber on the form
ANY HELP WITH THIS WOULD BE TRUELY APPRICIATED!!
Thanks in advance.
Melissa

Nov 13 '05 #1
2 1666
<me**********@y ahoo.co.uk> wrote in message
news:11******** ************@g4 9g2000cwa.googl egroups.com...
Hi

I am having trouble with ms-access and trying to determind whether or
not a row already exisitng in a particular table.

I have 3 tables namly Projects, ProjectsAttence dByContact,
ContactDetails
Defined as below.

Projects ProjectsAttende dByContact ContactDetails
------------ -------------------------- ------------------
*ProjectID *ProjectID *RefrenceNumber
ProjectName *RefrenceNumber Name
ThisProjectYes/No AttendedYes/No Surname
etc. etc.

What I am trying to do is allow a contact to attend many projects.

I have a form which has the Refrence number on it. So when I move to
the next record on the form I'd like to check if the combination of
ProjectID and RefrenceNumber exists in the ProjectsAttende dByContact
table - and if not to insert this combination into the table.

(I should have noted that the field onthe Projects table called
ThisProjectYes/No denotes which onthe list of projects we are currently
dealing with)

The SQL that I have been working on looks like this::
SELECT 5 AS Expr1, Projects.Projec tID AS Projects_Projec tID,
Projects.Projec tName, Projects.ThisPr oject
FROM Projects
WHERE (((5) Not In (select RefrenceNumber from
ProjectsAttende dByContact)) AND ((Projects.Proj ectID)<>Exists (select
ProjectID from ProjectsAttende dByContact)) AND
((Projects.This Project)=Yes));

WHERE 5 would be the RefrenceNumber on the form
ANY HELP WITH THIS WOULD BE TRUELY APPRICIATED!!
Thanks in advance.
Melissa


The table ProjectsAttende dByContact (sometimes called a junction table)
should indicate which contact attended which project. Often a structure
like this would not need a AttendedYes/No field since you can often assume
that if there is no matching record for the project/contact combination this
is the same as having a 'no' in the field. The only time where the yes/no
field would be important is if you wanted to show three options:
Contact attended project (record in junction table marked yes)
Contact did not attend project (record in junction table marked no)
Not sure whether contact attended project (no record in junction table)
Is this really a requirement or, as the yes/no field indicates, do you just
need two possibilities?

Additional comments:
Don't give your field names reserved words like 'Name'
Don't mis-spell 'reference' as 'refrence' - it will cause you (or future
developers) frustration

If you need further help, post back letting us know what the purpose of the
forms are, e.g. this is a form bound to the contacts table so I can look up
a contact, see what projects he attended ... etc
Nov 13 '05 #2
Hi Justin

Thank you very much for your help and comments.
I am basically using these tables in the exact manor you have asked
about.

I am setting up a DB where only the ContactDetails table has common
data between Projects. For each project then relating data such as
eventsAttended, commentsRespons es etc. is compeletly diffrent. So what
i have done is to create a base DB with common tables for DATA. Then
multiple other DB files which relate to each Project. [this have linked
tables bay to the common data in the DATA file]

The field onthe Projects table ThisProject - is a boolean field which
is set to yes only for the current project that a file represents.

Thus on the form I am talking about, I want to add a check box which
users are able to populate for the current project. (when the enter a
yes or no it will populate the ProjectAttended ByContact table - which
is shared across all projects)

Hope this gives more information into what I am trying to do.
Thanks
Melissa

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2718
by: mudge | last post by:
Hello, I have a mysql table. Two columns in the table are used to pull out stories from the table. One of the columns stands for categories of the stories, and the other column is the primary key and has the id for each story. I am thinking of writing queries like this:
9
5060
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to access them and automatically they can not continue their works. I have tried using the following code, but it does not work. I always got the error :
10
125444
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use : set @pCode='A1','A2','A3' but get an error : Incorrect syntax near ','
8
2579
by: Rob Mazur | last post by:
Hi. I'm trying to create a query that pulls information from 3 seperate tables. Here's how I want it to work: User is prompted for SSN Table 1: SSN Name Gender
7
2943
by: am72de | last post by:
Hi all, I've posted this problem some weeks ago, but noone had a solution. Perhaps now someone could help me. I have the following tables: Create Table T1 ( ID1 int Not Null , ID2 int Not Null
2
31482
by: RamaKrishna Narla | last post by:
In MS SQL Server, I have the following tables with some data in it. create table table1 ( column1 varchar(32), column2 int not null, column10 varchar(255), ..... primary key (column1, column2), );
6
35567
by: Mike S | last post by:
Hi all, A (possibly dumb) question, but I've had no luck finding a definitive answer to it. Suppose I have two tables, Employees and Employers, which both have a column named "Id": Employees -Id -FirstName -LastName
2
6542
by: Exick | last post by:
This is more of a minor annoyance/curiosity than a real problem, but I'm wondering if anyone here can provide some answers. I have a form bound to a table with lots of controls on it that are bound to fields of said table. I also have a combo box on the form that is unbound. I'm using it purely as a search mechanism. Anyway, the combo box dropdown is populated with data from a SQL query. There are 5 fields total, only the first 2 are...
1
5363
by: Sonny | last post by:
Hi, Would like to know the performance differenece between Multi-column Index vs Single Column Indexes. Let's say I have a table with col1, col2, col3 along with a primary key column and non-indexed columns. In queries, I will use col1, col2, and col3 together and some times just one or two of these three columns. My questions is, should I create one index contains col1, col2, and col3, or create 3 seperated columns. I.e. each column...
4
3533
by: drktmplr11 | last post by:
Hi, this is my first post here at the forums, and I am looking for assistance with what looks to be a syntax error within my code. I am attending FIU, and looking to broaden my understanding of programming with engineering applications. The class is an introduction to C++ with engineering emphasis. The bubble_sort function was provided by the professor. The other code was authored by myself. My question refers to calling a two dimensional...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.