0

I have to load some data into a temporary table, but the data is never uniform, the datatype and number of columns will always be different.

Is there an SQL command that will automatically create table specifications based on data that will be loaded into it?

3
  • This is confusingly vague. What kind of data? Can you give examples of some types and columns? Commented Jan 27, 2012 at 21:32
  • Surely there's some uniformity to the data, Some commonality or pattern to it. If not, how would this data be useful? Otherwise, if it's random data, perhaps a database is not an appropriate vessel for it? Commented Jan 27, 2012 at 21:35
  • @EtiennePerot The data will be a mix of numbers or text or varchar etc, Number of columns will also not be know. I'm not too sure that it's necessary for the right datatypes be specified the table, it might work just as well if all the columns were text Commented Jan 27, 2012 at 21:36

2 Answers 2

3

Assuming that you're populating it from a query, you can use the syntax CREATE TABLE tablename SELECT ...; see §12.1.14.1. CREATE TABLE ... SELECT Syntax in the MySQL 5.6 Reference Manual.

Sign up to request clarification or add additional context in comments.

1 Comment

I think you're the only one who actually answered his question.
0

SELECT ... INTO should do what you want.

4 Comments

Yikes, I think you are getting downvoted by the w3schools police.
This requires the table to be created beforehand. The question is to do it in a way such that the table gets created on the fly
@xbonez - no it doesn't, SELECT INTO will create the table during the operation. It does require a SQL source, though.
MySQL doesn't support that. See dev.mysql.com/doc/refman/5.6/en/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.