Solved

create a joint primary key for a access table?

Posted on 2004-09-01
3
1,061 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
Comment Utility
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
Comment Utility

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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now