通俗易懂讲解MySQL数据库的增删改查
创建数据库CREATE DATABASE database_name创建表CREATE TABLE `user` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;删除表DROP TABLE IF EXISTS `user`;添加字段:"ALTER TABLE`user` ADD`id` int(11) NOT NULL DEFAULT '0'COMMENT 'ID'"ALTERTABLE`user`ADD`name` VARCHAR( 20)CHARACTERSET utf8 COLLATE utf8_general_ci NULLDEFAULT NULLCOMMENT'姓名'删除字段ALTER TABLE`user` DROP column name重命名ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;修改类型alter table t1 change b b bigint not null;alter table infos change list list tinyint not null default '0';加索引alter table t1 rename t2;mysql> alter table tablename change depno depno int(5) not null;mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]);mysql> alter table tablename add index emp_name (name);加主关键字的索引mysql> alter table tablename add primary key(id);加唯一限制条件的索引mysql> alter table tablename add unique emp_name2(cardnumber);删除某个索引mysql>alter table tablename drop index emp_name;修改表:Thinkphp3.2中添加字段,如:M('admin')->execute("ALTER TABLE`admin` ADD`id` int(11) NOT NULL DEFAULT '0'COMMENT 'ID'");M('admin')->execute("ALTER TABLE`admin` ADD`name` varchar(20) DEFAULT NULLCOMMENT '姓名'");以上就是通俗易懂讲解MySQL数据库的增删改查的详细内容,更多请关注小潘博客其它相关文章!