Solved

automatically generated text fields in MySQL

Posted on 2016-09-13
4
13 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
  • 2
4 Comments
 
LVL 51

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 51

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now