automatically generated text fields in MySQL

How do I create a test  auto-generated field in a MySQL table? Can this field be used as a primary key? If so, what is the syntax for the create statement?

For example

Create table test (
text_id varchar(50) not null generated,
primary key (text_id));
chonabrahamAsked:
Who is Participating?
 
Julian HansenCommented:
You can use a UUID() default value
create table `ee`.`TableName1`( 
   `id` char(40) DEFAULT 'UUID()' , 
   `Name` varchar(100) 
 )

Open in new window

0
 
Julian HansenCommented:
What do you mean by auto generated?
For a primary key the field must be unique - you can use an autonumber but this is an int field?

Not sure what you are asking?
0
 
chonabrahamAuthor Commented:
can you have a Pk that is varchar and have MySQL generate the unique characters? How do you get MySQL to generate a unique varchar combo to use as the value for any field?
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.

All Courses

From novice to tech pro — start learning today.