Generating DDL statements of database from Google Cloud Sql using eclipse cause issue in script?
Asked Answered
R

2

25

I connected to a Google Cloud SQL database from eclipse using Data Source explorer. But when I generate DDL of that database using its option Generate DDL, I can't get the AUTO_INCREMENT in my script but get the corresponding primary key.

How would i go about getting the AUTO_INCREMENT in my script?

Refresh answered 21/6, 2012 at 12:17 Comment(4)
Are you using the Google Plugin for Eclipse?Trothplight
@ Neil H, yes i'm using Google PluginRefresh
I suggest that you reread your question and try to phrase it differently so that it is clearer what you are asking otherwise people will vote to close it as Not A Question. You just need to add a couple of more sentences instead of trying to explain everything in one sentence (the second one).Poplar
surely the primary key should be an auto increment as it should be the id of the row? (for all your tables) ++ could you give an example of what you are trying to do here?Purveyance
A
1

While this is not directly answering the question, I believe it will provide a solution to the root goal: Extracting the DDL.

Assumption: The following is a shell script, so an appropriate environment (OS X, Linux, cygwin) is required

Steps:

  1. Install the command line scripts (follow the instructions here)
  2. Create the following custom script in the same directory as the google_sql.sh:

    GOOGLE_CLOUD_SQL_INSTANCE=test:test
    
    echo "SELECT CONCAT('SELECT CONCAT(\"SHOW CREATE TABLE ',schema_name,'.\",table_name,\";\") \"select \\\\\"use ',schema_name,';\\\\\";\" FROM information_schema.tables WHERE table_schema = \"',schema_name,'\";') 'use information_schema;' FROM SCHEMATA WHERE schema_name NOT IN ('information_schema','mysql','performance_schema');" >> $$.1.get_schema.sql
    
    ./google_sql.sh $GOOGLE_CLOUD_SQL_INSTANCE information_schema < $$.1.get_schema.sql > $$.2.show_create.sql
    
    ./google_sql.sh $GOOGLE_CLOUD_SQL_INSTANCE information_schema < $$.2.show_create.sql > $$.3.sql.out
    
    ./google_sql.sh $GOOGLE_CLOUD_SQL_INSTANCE information_schema < $$.3.sql.out > $$.4.create.raw
    
    awk -F"  " '/Table Create Table/{print "";}
     /CREATE/{sub(/^..*CREATE TABLE/,"CREATE TABLE");print $0}
     $1 == "" {print $0}
     /^\)/{print $0";"}
     /^use/{print $0}' $$.4.create.raw > $GOOGLE_CLOUD_SQL_INSTANCE.ddl.sql
    
    rm $$.*
    
  3. Replace "test:test" in the script with your Google Cloud instance identifier

  4. Execute the script to produce a file of the format "test:test".ddl.sql which will have the DDL for all tables in all databases.
Apprehension answered 20/11, 2012 at 17:55 Comment(0)
P
0

Maybe this helps:

Google Cloud SQL Step 3

Another example of using DDL is this:

CREATE TABLE tabelle
(
feld datentyp [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [COMMENT 'string'],
CONSTRAINT name
  PRIMARY KEY (feld1, feld2, ...)
  FOREIGN KEY (feld1, feld2, ...) REFERENCES tabelle (feld1, feld2)
)

Source: http://www.tinohempel.de/info/info/datenbank/sql_tabelle.htm
It's in German but the examples are very good!

Hope I understood your question right and this helps!

Praiseworthy answered 17/11, 2012 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.