Database: MySQL create table, int, varchar, bit, double, TIMESTAMP type, specify the character set and engine, the device table devices

1. Create auto-increment id int primary key field

CREATE TABLE `test` (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '序号',
  PRIMARY KEY (`id`)
);

Here Insert Picture Description

2. Create a device common type varchar

CREATE TABLE `test` (
  `device` varchar(255) NOT NULL COMMENT '设备'
);

Here Insert Picture Description

3, create device_status the bit type

CREATE TABLE `test` (
  `device_status` bit(1) NOT NULL COMMENT '状态'
);

Here Insert Picture Description

4, the creation of a double temperature

CREATE TABLE `test` (
  `temperature` double(4, 2) NOT NULL COMMENT '温度'
);

Here Insert Picture Description

5. Create a TIMESTAMP type of time

5.1, creation time

CREATE TABLE `test` (
  `time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
);

Here Insert Picture Description

5.2 update

CREATE TABLE `test`  (
  `time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
);

Here Insert Picture Description

6, specify the engine and character set

CREATE TABLE `test`  (
  `time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间'
) ENGINE = InnoDB CHARACTER SET = utf8;

Here Insert Picture Description

7, create a device table devices

CREATE TABLE `devices` (
	`id` INT ( 11 ) UNSIGNED NOT NULL auto_increment COMMENT '序号',
	`device` VARCHAR ( 255 ) NOT NULL COMMENT '设备名称',
	`device_status` bit ( 1 ) NOT NULL COMMENT '设备状态',
	`temperature` DOUBLE ( 4, 2 ) NOT NULL COMMENT '温度',
	`time` TIMESTAMP ( 0 ) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
	`update_time` TIMESTAMP ( 0 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
	PRIMARY KEY ( `id` ) 
) engine = INNODB CHARACTER SET = utf8;

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43731793/article/details/93406962