1.取下一个自增字段的值:
select auto_increment from information_schema.`TABLES` where TABLE_NAME='t_exampaper';
2.查询表是否存在:
select `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_SCHEMA`='dbname' and `TABLE_NAME`='tablename';
3.如果表不存在就建立这个表,那么可以直接用 create table if not exists tablename 这样的指令来建立,不需要先去查询表是否存在。
4.查询表字段是否存在:
select COLUMN_NAME from information_schema.COLUMNS where TABLE_SCHEMA='database_name' and TABLE_NAME='table_name' and COLUMN_NAME='column_name';
select auto_increment from information_schema.`TABLES` where TABLE_NAME='t_exampaper';
2.查询表是否存在:
select `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_SCHEMA`='dbname' and `TABLE_NAME`='tablename';
3.如果表不存在就建立这个表,那么可以直接用 create table if not exists tablename 这样的指令来建立,不需要先去查询表是否存在。
4.查询表字段是否存在:
select COLUMN_NAME from information_schema.COLUMNS where TABLE_SCHEMA='database_name' and TABLE_NAME='table_name' and COLUMN_NAME='column_name';