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?

Emil
  • 7,220
  • 17
  • 76
  • 135
Master Mind
  • 2,386
  • 3
  • 31
  • 48
  • Are you using the Google Plugin for Eclipse? – Neil H Jul 30 '12 at 16:01
  • @ Neil H, yes i'm using Google Plugin – Master Mind Jul 31 '12 at 12:22
  • 1
    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). – Michael Dillon Nov 15 '12 at 06:15
  • 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? – Steve P Nov 15 '12 at 09:11

2 Answers2

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.
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
Drew
  • 6,311
  • 4
  • 44
  • 44
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!

Helder Pereira
  • 5,522
  • 2
  • 35
  • 52