0

I am new at SQL and am having a little of trouble

This is my code

CREATE TABLE dataType(
    Charater CHAR(250),
    VariaChar VARCHAR(250),
    STRING TEXT,
    interger INT(50),
    Floating FLOAT(50, 3),
    fractions DECIMAL(50, 3),
    today DATETIME("2018-10-07 12:55:20"),
    watch TIME("12:55:20"),
    centry YEAR(2018)
);

Basically, I am trying to make a table that has three type of text data, number data, and date data. The problem is when I run the code I get this error:

Error SQL query:

CREATE TABLE dataType(
Charater CHAR(250),
VariaChar VARCHAR(250),
STRING TEXT,
interger INT(50),
Floating FLOAT(50, 3),
fractions DECIMAL(50, 3),
today DATETIME("2018-10-07 12:55:20"),
watch TIME("12:55:20"),
centry YEAR(2018) )
MySQL said:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"2018-10-07 12:55:20"),
watch TIME("12:55:20"),
centry YEAR(2018)
)' at line 8*

I do not know what may be causing this problem. Thank you for thanking your time to try to assist me even if this has an obvious solution.

2

2 Answers 2

2

Use DATETIME instead of DATETIME("2018-10-07 12:55:20"),if you want to set the default value of today,you need to use default

CREATE TABLE dataType(
    Charater CHAR(250),
    VariaChar VARCHAR(250),
    STRING TEXT,
    interger INT(50),
    Floating FLOAT(50, 3),
    fractions DECIMAL(50, 3),
    today DATETIME,
    watch TIME,
    centry YEAR
);
Sign up to request clarification or add additional context in comments.

1 Comment

THANK YOU SO MUCH!!! I thought that you had to add value to datetime, time, and year but you do not. Thanks for giving me a straight forward answer!!
2

Your default syntax is off. Assuming you are using MySQL 5.6.5 or later, the following should work:

CREATE TABLE dataType(
    Charater CHAR(250),
    VariaChar VARCHAR(250),
    STRING TEXT,
    interger INT(50),
    Floating FLOAT(50, 3),
    fractions DECIMAL(50, 3),
    today DATETIME DEFAULT '2018-10-07 12:55:20',
    watch TIME DEFAULT '12:55:20',
    centry YEAR DEFAULT 2018
);

If you don't want default values for the final three fields, then don't use them:

today DATETIME,
watch TIME,
centry YEAR

Comments

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.