mysql table schema to actual table -


i'm new databases, apologies if incredibly stupid quesiton. sent schema of mysql table in body of email. looks this, except has many more rows:

+-------------------------+---------------+------+-----+---------+-------+ | field                   | type          | null | key | default | | +-------------------------+---------------+------+-----+---------+-------+ | _id                     | varchar(40)   | no   | foo | null    |       | | foo                     | text          | yes  |     | null    |       | | bar                     | text          | yes  |     | null    |       | | baz                     | text          | yes  |     | null    |       | | qux                     | datetime      | yes  |     | null    |       | +-------------------------+---------------+------+-----+---------+-------+ 

i need create table locally before reading in actual data, in accompanying tsv file. i'd rather not create table schema manually, lot of columns. there way automatically using schema sent?

there no way automatically convert ascii-art table of form sql create statement.

if bored , inclined so, suppose write utility parse input , generate output.

you either have create table query (see create), or use administrative front-end such phpmyadmin enter information in more human-friendly manner (i believe phpmyadmin has graphical designer feature).

some other dbms's have table generation tools built in front-ends too, e.g. ms sql server management studio has nice graphical table builder.

by way, pick nits, mean lot of columns, not rows.


edit: fun, here quick linux shell script converts of informational portion of table sql statement (command line parameter input file name):

#!/bin/sh echo "create table mytable (" cat "$1" | awk '{ split($0,a,"|"); print a[2] a[3] (match(a[4],"no")?"not null":"") " default" a[6] ","; }' | tr -s " " echo ");" 

the following input file:

| _id                     | varchar(40)   | no   | foo | null    |       | | foo                     | text          | yes  |     | null    |       | | bar                     | text          | yes  |     | null    |       | | baz                     | text          | yes  |     | null    |       | | qux                     | datetime      | yes  |     | null    |       | 

generates following output:

create table mytable (  _id varchar(40) not null default null ,  foo text default null ,  bar text default null ,  baz text default null ,  qux datetime default null , ); 

but still have remove foo line manually , replace _id foo (and not null default null odd, don't know of mysql accept null default on not null column). doesn't care key column. have manually delete last comma. of work, though.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -