开发者

How to define the default values for a column when creating tables in MySQL?

开发者 https://www.devze.com 2023-03-01 16:45 出处:网络
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?

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
);


IsObsolete           CHAR(1) NOT NULL DEFAULT 'N'


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
);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消