Mysql basic syntax one

 
CREATE TABLE `t_student`(
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'student ID',
`student_num` VARCHAR(20) NOT NULL DEFAULT '' COMMENT 'student number',
`name` VARCHAR(15) NOT NULL DEFAULT '' COMMENT 'student name',
`sex` VARCHAR(10) NOT NULL DEFAULT '' COMMENT 'student gender',
`grade` INT(2) NOT NULL DEFAULT 0 COMMENT 'student grade',
`class_num` INT(2 ) NOT NULL DEFAULT 0 COMMENT 'student class',
`birthday` DATE NOT NULL DEFAULT '0000-00-00' COMMENT 'student birthday',
`is_good_student` INT(2) NOT NULL DEFAULT 0 COMMENT 'whether the student is a good student 1 yes 0 no',
`created_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'created time',
`last_modified_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time',
PRIMARY KEY (`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='student information table';

 First of all, the table name and column name should be enclosed in single quotation marks, then the problem is coming. This single quotation mark must be the single quotation mark under Esc;

The single quotation mark used for the default value and remark is the single quotation mark on the same key as the double quotation mark, pay attention to distinguish;

AUTO_INCREMENT can be understood as the meaning of automatic increment. Each time a record is added, the value will automatically increase by 1. You can also use the "AUTO_INCREMENT=n" option to specify an auto-incrementing initial value.

COMMENT Set remarks Note that the method of field annotations is different from that of table annotations. Table annotations have an equal sign

 NOT NULL The field cannot be empty

DEFAULT sets the default field,  DEFAULT 0 for int type; DEFAULT '' for varchar type  ; DEFAULT '0000-00-00' for Date type  ; some rules can be summarized from this.

CHARSET=utf8 set field encoding

PRIMARY KEY (`id`) sets the primary key

[CONSTRAINT foreign key name] set foreign key

ENGINE=INNODB

The storage engine is innodb. nnoDB is the first data storage engine on MySQL to provide foreign key constraints. In addition to providing transaction processing,
InnoDB also supports row locks, providing the same consistent unlocked reads as Oracle, which can increase the number of concurrent users and improve
performance, without increasing the number of locks. InnoDB is designed to maximize performance when processing large volumes of data, and its CPU utilization
rate is the most efficient of all other disk-based relational database engines.

InnoDB is a complete database system placed in the background of MySQL. InnoDB has its own buffer pool, which can buffer data and indexes
, InnoDB also stores data and indexes in the tablespace, which may contain several files, which is completely different from the MyISAM table.
In MyISAM, tables are stored in separate files, and the size of InnoDB tables is only limited by the size of the operating system file, generally
 2GB。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326557711&siteId=291194637