• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1374
  • Last Modified:

MySQL 5.0: create GUID column

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
newbieal
Asked:
newbieal
  • 3
2 Solutions
 
gregfortuneCommented:
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
 
newbiealAuthor Commented:
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
 
gregfortuneCommented:
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
 
gregfortuneCommented:
Gah... For each *row* in the table.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now