Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

automatically generated text fields in MySQL

Posted on 2016-09-13
4
Medium Priority
?
24 Views
Last Modified: 2016-10-03
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));
0
Comment
Question by:chonabraham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41796906
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
 

Author Comment

by:chonabraham
ID: 41797106
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
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 2000 total points (awarded by participants)
ID: 41797315
You can use a UUID() default value
create table `ee`.`TableName1`( 
   `id` char(40) DEFAULT 'UUID()' , 
   `Name` varchar(100) 
 )

Open in new window

0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

648 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