0

Can I do some thing like this in MySQL? I want to have a unique id generate by the database automatically but not using auto_increment.

CREATE TABLE cust(
     CustomerID uniqueidentifier NOT NULL DEFAULT newid(),
     Fax varchar(15) NULL
);

I have try this, but there has an error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'uniqueidentifier NOT NULL DEFAULT newid(), Fax varchar(15) NULL )' at line 2

Marc Delisle
  • 8,879
  • 3
  • 29
  • 29
We Rub Chan
  • 205
  • 1
  • 5
  • 14

1 Answers1

1

You can use UUID() to create a Unique Value.

Eg.

INSERT INTO cust (CustomerID, Fax) Values(UUID(), "21312312");
Jenson M John
  • 5,499
  • 5
  • 30
  • 46