Solved

create a joint primary key for a access table?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query help 3 78
Delete old Sharepoint backups 2 54
SSIS Combine projects into one 2 36
How to combine two oracle database together 9 77
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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.
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…

751 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