Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

create a joint primary key for a access table?

Posted on 2004-09-01
3
Medium Priority
?
1,109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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