Solved

automatically generated text fields in MySQL

Posted on 2016-09-13
4
21 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 57

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 57

Accepted Solution

by:
Julian Hansen earned 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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