Solved

create a joint primary key for a access table?

Posted on 2004-09-01
3
1,068 Views
Last Modified: 2012-05-05
following is the .ddl file, how to create a joint primary key?

create table bookcmptable (

  isbn varchar(255),
  copyNumber integer,
  title varchar(255),
  author varchar(255),
  studentkey integer,
  primary key (isbn, copyNumber)
);
0
Comment
Question by:she1
3 Comments
 
LVL 4

Expert Comment

by:chipple
ID: 11960311
By "joint primary key", you mean a primary key on several fields?
Your CREATE TABLE query already contains one. But if you want to add the primary key separately, try the following.

For example, if you did:

create table bookcmptable (
  isbn varchar(255),
  copyNumber integer,
  title varchar(255),
  author varchar(255),
  studentkey integer
);

You can do:

ALTER TABLE bookcmptable
ADD CONSTRAINT PK_bookcmptable PRIMARY KEY (isbn, copyNumber);

Good luck!
0
 

Expert Comment

by:Naveen13
ID: 11994180

Hi if you create a table with our a composite primary key..
You can use alter statement  to a modify the table

ALTER TABLE bookcmptable ADD PRIMARY KEY (isbn, copyNumber);

This helps you
naveen
0
 
LVL 1

Accepted Solution

by:
Medfly earned 30 total points
ID: 11999347
The way you have written your Create Table command.. you have already defined a "composite" or "joint" primary key.
---------------------------------------------------
create table bookcmptable (

  isbn varchar(255),
  copyNumber integer,
  title varchar(255),
  author varchar(255),
  studentkey integer,
  primary key (isbn, copyNumber)    <== PRIMARY KEY
);
---------------------------------------------------

The only thing I would do differently is name your Primary Key Constraint which would change your syntax to look something like

create table bookcmptable (

  isbn varchar(255),
  copyNumber integer,
       CONSTRAINT pk_bookcmptable PRIMARY KEY (isbn, copyNumber),
  title varchar(255),
  author varchar(255),
  studentkey integer,
  );

Does this help?  Or are you talking about making a Foreign Key reference to another table?
Cheers!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now