常用Sql
清泛原创
mysql:drop table if exists tablename;
不能写成
drop table tablename if exists tablename;
mysql:建立索引Sql
CREATE TABLE tablename (
`ID` decimal(18,0) NOT NULL COMMENT '递增ID',
`FIELD_1` varchar(32) NOT NULL COMMENT '字段1',
`FIELD_2` varchar(32) NOT NULL COMMENT '字段2',
PRIMARY KEY (`ID`),
KEY `FIELD_1` (`FIELD_1`), #单索引
KEY `FIELD_1_2` (`FIELD_1`, `FIELD_2`), #联合索引
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql:插入或更新(根据主键,存在Update,否则Insert)
replace into tablename(key,field1) values(val,val1); #语法同insert into
不能写成
drop table tablename if exists tablename;
mysql:建立索引Sql
CREATE TABLE tablename (
`ID` decimal(18,0) NOT NULL COMMENT '递增ID',
`FIELD_1` varchar(32) NOT NULL COMMENT '字段1',
`FIELD_2` varchar(32) NOT NULL COMMENT '字段2',
PRIMARY KEY (`ID`),
KEY `FIELD_1` (`FIELD_1`), #单索引
KEY `FIELD_1_2` (`FIELD_1`, `FIELD_2`), #联合索引
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql:插入或更新(根据主键,存在Update,否则Insert)
replace into tablename(key,field1) values(val,val1); #语法同insert into