?
Solved

MySQL 5.0: create GUID column

Posted on 2008-11-11
4
Medium Priority
?
1,342 Views
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?
0
Comment
Question by:newbieal
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
gregfortune earned 1500 total points
ID: 22932516
CREATE TABLE temp (
  ID INT(11)  NOT NULL auto_increment,
  another_column char(10) NULL,
  yet_another_column char(15) NULL,
  PRIMARY KEY (ID)
);

The important pieces are the PRIMARY KEYpart and auto_increment
0
 
LVL 4

Author Comment

by:newbieal
ID: 22932583
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.
0
 
LVL 2

Assisted Solution

by:gregfortune
gregfortune earned 1500 total points
ID: 22933129
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.
0
 
LVL 2

Expert Comment

by:gregfortune
ID: 22933133
Gah... For each *row* in the table.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 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