Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Posts
    225

    Unanswered: Make Table Query setting a Primary Key

    I am trying to create a new Table using a MakeTable Query

    using the following sql:

    Code:
    SELECT qCPPlannedStopsOnTargetTotals.WeekNumber, qCPPlannedStopsOnTargetTotals.Line, qCPPlannedStopsOnTargetTotals.Description AS Above, qCPPlannedStopsOnTargetTotals.[%] INTO mkCPPlannedStopsAbove
    FROM qCPPlannedStopsOnTargetTotals
    WHERE (((qCPPlannedStopsOnTargetTotals.Description)="Above"))
    ORDER BY qCPPlannedStopsOnTargetTotals.WeekNumber DESC;
    However i want the new table to have a Primary Key, (Week Number) can i set this as the table is made?

    Please help

    Andy

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    This is probabyl not what you're looking for but it may come in handy.
    Unique index (numbers) - so not really declaring your primary key as what you want. Starting point perhaps, or a "there's no other way" answer
    Code:
    CREATE UNIQUE INDEX index_name
    ON table_name (column_name)
    George
    Home | Blog

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Amendment to the above:
    Code:
    CREATE TABLE Students (
    StudentID INTEGER PRIMARY KEY NOT NULL,
    FirstName varchar(20),
    LastName varchar(20),
    HomePhone varchar(16));
    I think you should easily be able to set the ID as char or whatever is needed.
    Test first
    Also noticing that your code is a SELECt, not a CREATE

    EDIT: OR....
    Code:
    CREATE TABLE Students (
    StudentID INTEGER NOT NULL,
    FirstName varchar(20),
    LastName varchar(20),
    HomePhone varchar(16),
    PRIMARY KEY(StudentID));
    See this handy article.
    Last edited by gvee; 02-26-07 at 05:07.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •