22

What is the SQL to define DEFAULT values in MySQL?

In the code below what needs to be added / changed to give IsObsolete a default value of N?

CREATE TABLE Team
(
    TeamId              CHAR(16) NOT NULL,
    DateCreated          TIMESTAMP NOT NULL,
    IsObsolete           CHAR(1) NOT NULL DEFAULT N,
    UpdateTime           TIMESTAMP NOT NULL
);
1
  • 1
    Super noob here, why CHAR(1) and not boolean? Commented Oct 2, 2013 at 16:02

3 Answers 3

24
IsObsolete           CHAR(1) NOT NULL DEFAULT 'N'
Sign up to request clarification or add additional context in comments.

2 Comments

hehe, thanks...overlooked something so simple. Appreciate the help
Happens :D. I'm glad to help.
10

You probably want to put quotes around it:

CREATE TABLE Team
(
    TeamId              CHAR(16) NOT NULL,
    DateCreated          TIMESTAMP NOT NULL,
    IsObsolete           CHAR(1) NOT NULL DEFAULT 'N',
    UpdateTime           TIMESTAMP NOT NULL
);

1 Comment

+1 looks like your answer came in a few seconds later. Thanks for the help.
1

If your are changing your structure via phpMyAdmin, you should just type in the char (e.g N) as opposed to 'N'

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.