mysql 建表语句

最近项目在用mysql语句

指定非空,默认值为空字符串    NOT NULL  DEFAULT ‘‘

建表

CREATE TABLE  IF NOT EXISTS `ims_test` (

`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`sid` int(11) NOT NULL DEFAULT 0 COMMENT ‘店铺id‘ ,
`name` varchar(120) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ‘‘ COMMENT ‘名称‘ ,
`remark` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘备注‘ ,
`num` int(11) NOT NULL DEFAULT 0 COMMENT ‘数量‘ ,
`money` decimal(8,2) NOT NULL DEFAULT 0 COMMENT ‘金额‘ ,
PRIMARY KEY (`id`),
UNIQUE INDEX `id` (`id`) USING BTREE ,
INDEX `sid` (`sid`) USING BTREE
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
COMMENT=‘测试表‘;

追加索引  

ALTER TABLE `ims_test` ADD INDEX sid ( `sid` )

追加字段

ALTER TABLE `ims_coupon`
ADD COLUMN `img` varchar(120) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ‘‘ COMMENT ‘图片‘ AFTER `color`;

相关推荐