1. Create auto-increment id int primary key field
CREATE TABLE `test` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '序号',
PRIMARY KEY (`id`)
);
2. Create a device common type varchar
CREATE TABLE `test` (
`device` varchar(255) NOT NULL COMMENT '设备'
);
3, create device_status the bit type
CREATE TABLE `test` (
`device_status` bit(1) NOT NULL COMMENT '状态'
);
4, the creation of a double temperature
CREATE TABLE `test` (
`temperature` double(4, 2) NOT NULL COMMENT '温度'
);
5. Create a TIMESTAMP type of time
5.1, creation time
CREATE TABLE `test` (
`time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
);
5.2 update
CREATE TABLE `test` (
`time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
);
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;
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;