MySQL builds a self-increment primary key insert, and automatically inserts the current time

Source: Internet
Author: User

MySQL uses these two fields, almost all of them are necessary.

Used to be automatically established, and now hand-built, it is necessary to find information to fix it.

Reference URL:

http://blog.csdn.net/Weicleer/article/details/47608289

Http://www.cnblogs.com/lhj588/p/4245719.html

==============================

After the table is established, how to insert values is also an issue.

==============================

When there is a self-growing primary key in the data table, when inserting a statement with an SQL INSERT statement with an ID column value record;

      1. If the value of the column is specified, the newly inserted value cannot be duplicated with the existing value and must be greater than the largest of the values;
      2. You can also do not specify the value of the column, only the value of the other columns inserted, let the ID or MySQL self-increment to fill in;
        This is the case when inserting, two workarounds:
        ① can set the value of the ID to null or 0, so the child MySQL will do its own processing
        ② manually specify the columns that need to be inserted, and do not insert data for this field!

When inserting the current time value, the 2-2 method does not specify the column value and column data, and MySQL will take care of it.

For my scenario:

The table is like this:

CREATE TABLE' Pmlog ' (' ID ')int( One) not NULLauto_increment, ' Deployname 'varchar(255) not NULL, ' AppName 'varchar(255), ' SiteName 'varchar(255), ' ipAddress 'varchar(255) not NULL, ' Envtype 'varchar(255), ' UserName 'varchar(255) not NULL, ' Operationtype 'varchar(255), ' Operationno 'varchar(255), ' Logcontent 'varchar(2048), ' Logdatetime 'datetime NULL DEFAULT Current_timestamp,  PRIMARY KEY(' id '),) ENGINE=InnoDBDEFAULTCHARSET=UTF8 COLLATE=Utf8_unicode_ci;

When inserting data manually, use the following command.

INSERT  into' Pmlog ' (Deployname, AppName, SiteName, ipAddress, Envtype, UserName, Operationtype, Operationno, logcontent)VALUES('DeployName5','AppName5','SiteName5','ipAddress1.3.5','Envtypefat','USERNAMECCC','OperationType1','OperationNo5','logcontentffffffff55555555fffffffffff');

MySQL builds a self-increment primary key insert, and automatically inserts the current time

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.