1、创建id字段int自增主键
CREATE TABLE `test` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '序号',
PRIMARY KEY (`id`)
);

2、创建device普通varchar类型
CREATE TABLE `test` (
`device` varchar(255) NOT NULL COMMENT '设备'
);

3、创建device_status的bit类型
CREATE TABLE `test` (
`device_status` bit(1) NOT NULL COMMENT '状态'
);

4、创建temperature的double类型
CREATE TABLE `test` (
`temperature` double(4, 2) NOT NULL COMMENT '温度'
);

5、创建time的TIMESTAMP类型
5.1、创建时间
CREATE TABLE `test` (
`time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
);

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

6、指定引擎和字符集
CREATE TABLE `test` (
`time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间'
) ENGINE = InnoDB CHARACTER SET = utf8;

7、创建一个设备表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;


