MySQL table field Set default value

Source: Internet
Author: User
Tags command line datetime

Environment

MySQL 5.1 + command line tools

Problem

MySQL table field Set default value

Solve

--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 is not valid--time_d time is not  
null default Curtime (),  
--date_e date is not null default Curdate (),  
--datetime_ f datetime not NULL DEFAULT now (),

Summarize

int type: The default value must also be an integral type, and no () bracket behind default.

Char type: The default value is to use single quotes.

DateTime type: the Now () function returns the current date time with ' Yyyy-mm-dd HH:MM:SS ', and can be saved directly to the DateTime field. Using system defaults is not supported.

Date type: Curdate () returns today's date in ' YYYY-MM-DD ' format and can be stored directly in the Date field. Using system defaults is not supported.

Time Type: Curtime () returns the current period in ' HH:MM:SS ' format, which can be stored directly in the Duration field. Using system defaults is not supported.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/

Related Article

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.