MySQL table field settings default value (graphic tutorial and note details) _ MySQL

Source: Internet
Author: User
MySQL table field settings default value (graphic tutorial and attention details) bitsCN.com Environment
MySQL 5.1 + command line tool
Problem
MySQL table field settings default value
Solution

-- SQL:
Create table test (
I _a int NOT NULL DEFAULT 1,
Ts_ B timestamp NOT NULL DEFAULT NOW (),
C_c char (2) not null default '1'
);
-- The following SQL statements are invalid.
-- Time_d time not null default curtime (),
-- Date_e date not null default curdate (),
-- Datetime_f datetime not null default now (),


Summary
Int type: the default value must also be an integer, and no brackets () are left behind the default value.
Char type: single quotes are used by default.

DATETIME type: NOW () function returns the current date and time with 'yyyy-MM-DD HH: MM: SS', which can be saved directly to the DATETIME field. Default values are not supported.

DATE type: CURDATE () returns today's DATE in 'yyyy-MM-DD 'format and can be saved directly to the DATE field. Default values are not supported.

TIME type: CURTIME () returns the current TIME in 'hh: MM: SS' format and can be saved directly to the TIME field. Default values are not supported.
References
Mysql table field default value
An error occurred while creating a table using SQL statements.
For example, in mssql

Create table dnt_forums (
Aa int not null default (''),
Bb date not null default (getdate ()),
Cc char (50) not null default (null)
}

How can I modify the preceding SQL statement to be used in mysql?

Aa is an int type, and the default value must also be an integer. do not use parentheses after the default value.
The default value of the bb date type is not supported. it is changed to timestamp and the system time can be obtained through now ().
Cc cannot be empty (not null). Therefore, it cannot be null by default. you can change it to a null string.

Create table dnt_forums (
Aa int not null default 2,
Bb timestamp not null default now (),
Cc char (50) not null default''
);

Functions used by MySQL to obtain the current system time
Http://www.bitsCN.com/article/29124.htmbitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.