Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2014

    Unanswered: Newbie question about constraint

    I understand about constraints in general, but what I don't understand is using CONSTRAINT as a keyword. Please consider the following code:

    CREATE TABLE publishers
        pub_id CHAR(3)  NOT NULL,
        pub_name VARCHAR(20) NOT NULL,
        city CHAR(15)  NOT NULL,
        state VARCHAR(2) NOT NULL,
        country VARCHAR (15) NOT NULL,
        CONSTRAINT publishers_pk
            PRIMARY KEY (pub_id)
    My confusion is CONSTRAINT publishers_pk. What does that mean?

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    The CONSTRAINT clause names the constraint. This allows you to manage the constraint later.

    Depending on which MySQL version and which storage engine (myISAM, Inno-DB, etc.) you choose, MySQL may or may not honor constraints. If MySQL can't honor the constraint it will process the syntax without raising an error, but constraint violations will not be caught/prevented by the storage engine.

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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