MySQL 5.0: create GUID column

Posted on 2008-11-11
Last Modified: 2012-05-05
How can I create a column in a table that represents the PK and is a unique identifier, similar to GUID in SQL Server?
Question by:newbieal
    LVL 2

    Accepted Solution

    CREATE TABLE temp (
      ID INT(11)  NOT NULL auto_increment,
      another_column char(10) NULL,
      yet_another_column char(15) NULL,

    The important pieces are the PRIMARY KEYpart and auto_increment
    LVL 4

    Author Comment

    Yes, but this does not assign a guid value, or am I mistaken?  your example will just increment by 1 a regular integer.  I need a unique identifier assigned for each PK in the row/table.  Like the GUID in SQL Server.
    LVL 2

    Assisted Solution

    As you noted, auto_increment increments the valid in the ID column for each row. This happens when a new row is inserted.  As the row is inserted (don't specify a value for ID), the server figures out which ID to give it and adds that automatically for you.

    The unique portion of it is taken care of by the last line.  PRIMARY KEY(ID) identifies the primary key column and forces that column to be unique.

    Taking these two together, you get an automatically assigned, incrementing unique integer for each column in the table.
    LVL 2

    Expert Comment

    Gah... For each *row* in the table.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (…
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now