Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2014
    Posts
    2

    Unanswered: Make a table with a Primary Key

    I want to run a query to make a table, but at the same time adding a primary key to the table. The query only has two fields in it, the code and the quantity. I want the primary key to be on the code field. How can this be achieved?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you want Code to be a numeric (long integer), use:
    Code:
    CREATE TABLE [TableName]
        ( Code INTEGER NOT NULL CONSTRAINT PrimaryKey PRIMARY KEY,
          Quantity INTEGER NULL
        );
    If you want Code to be an Autonumber, use:
    Code:
    CREATE TABLE [TableName]
        ( Code COUNTER NOT NULL CONSTRAINT PrimaryKey PRIMARY KEY,
          Quantity INTEGER NULL
        );
    Note: Replace TableName by the actual name of the table you want to create.
    Have a nice day!

  3. #3
    Join Date
    Jun 2014
    Posts
    2
    What if the code is a text field?

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Change the data type of the column definition:
    Code:
    CREATE TABLE [TableName]
        ( Code TEXT(n) NOT NULL CONSTRAINT PrimaryKey PRIMARY KEY,
          Quantity INTEGER NULL
        );
    where n is the length of the Text column (1 to 255).

    Note: All the available data types are explained in Access help
    Have a nice day!

Tags for this Thread

Posting Permissions

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