Tom
Tom

Reputation: 45

Google Cloud SQL Datatypes

I just have a quick query. I am trying to create a database table (I have a cloud sql database using Google Cloud) I can create databases, tables and insert into them fine. But I am having trouble with one field. Do you know if there is mysql character type for date and/or time?

I am using the following query but the character types DATE, DATETIME AND TIMESTAMP will not work and the query is not successful:

CREATE TABLE entries (id INT(30) UNSIGNED AUTO_INCREMENT PRIMARY KEY,  firstName VARCHAR(30), surname VARCHAR(30), course VARCHAR(50), subject VARCHAR(50), level VARCHAR(50), checkIn DATETIME(50));

When I submit that I get the following error (which corresponds to the DATETIME character type, not the checkIn field name but the DATETIME character type):

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(50))

So basically do you know if there is a date or time character type for mysql that can be used in the cloud (with Google)?

Upvotes: 0

Views: 420

Answers (2)

Abhishekh Gupta
Abhishekh Gupta

Reputation: 6236

I think the syntax error you are getting is bcoz of big precision limit of DATETIME. So, try this:

CREATE TABLE entries (id INT(30) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                      firstName VARCHAR(30), 
                      surname VARCHAR(30), 
                      course VARCHAR(50), 
                      subject VARCHAR(50), 
                      level VARCHAR(50), 
                      checkIn DATETIME);

And the maximum precision limit for DATETIME in Mysql is 6 i.e., DATETIME(6)

Upvotes: 1

David Soussan
David Soussan

Reputation: 2736

There is no size parameter for DATETIME, or any other date /time data type and that is your error. Just specify DATETIME.

Upvotes: 1

Related Questions