MySQL Primary Key (Lab2.3) - MySQL Primary Key Summary in...

Info icon This preview shows pages 1–2. Sign up to view the full content.

MySQL Primary Key Summary : in this tutorial, you will learn how to use MySQL primary key constraint to create a primary key for the table. Introduction to MySQL primary key A primary key is a column or a set of columns that uniquely identifies each row in the table. The following are the rules that you must follow when you define a primary key for a table: A primary key must contain unique values. If the primary key consists of multiple columns, the combination of values in these columns must be unique. A primary key column cannot contain NULL values. It means that you have to declare the primary key column with NOT NULL attribute. If you don’t, MySQL will force the primary key column as NOT NULL implicitly. A table has only one primary key. Because MySQL works faster with integers, the primary key column’s type should be an integer type e.g., INT or BIGINT . You can choose a smaller integer type such as TINYINT , SMALLINT , etc., however you should make sure that the range of values of the integer type for the primary key is sufficient for storing all possible rows that the table may have.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '16
  • MYSQL , Foreign key, primary key, TINYINT

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern