Results 1 to 2 of 2
  1. #1
    Join Date
    May 2014
    Posts
    1

    Unanswered: Can Not Use NULL With Multi-Column Primary Key

    I have a table with columns (Make, Model and Year) that I want to use for a multi-column primary key. I have a text field for users to type in there search.

    Examples
    "DeLorean", Should retrive data from row 2.
    "DeLorean DMC-12 1983", Should retrive data from row 6.
    "DeLorean DMC-12", Should retrive data from row 3.

    I've read that the columns used to create the primary key can not be set to NULL even if you use DEFAULT NULL when the table is created. I've read that you can DEFAULT an empty string " " and may be "NULL" (still a string). I have a limited understanding with multi-column and need help.

    CREATE TABLE Autos (
    Make VARCHAR(50),
    Model VARCHAR(50),
    Year INT(11),
    PRIMARY KEY(Make, Model, Year)
    );

    1: INSERT INTO Autos (Make, Model, Year) VALUES (NULL, NULL, NULL);
    2: INSERT INTO Autos (Make, Model, Year) VALUES ("DeLorean", NULL, NULL);
    3: INSERT INTO Autos (Make, Model, Year) VALUES ("DeLorean", "DMC-12", NULL);
    4: INSERT INTO Autos (Make, Model, Year) VALUES ("DeLorean", "DMC-12", 1981);
    5: INSERT INTO Autos (Make, Model, Year) VALUES ("DeLorean", "DMC-12", 1982);
    6: INSERT INTO Autos (Make, Model, Year) VALUES ("DeLorean", "DMC-12", 1983);

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Haven't you already answered your non existent question....
    I've read that columns used to create the primary key can not be set to NULL
    ...unless its are there any good references on normalisation / normaling a table design
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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