您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

通俗易懂讲解MySQL数据库的增删改查

2024/6/18 6:55:21发布29次查看
创建数据库
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'"alter table `user` add `name` varchar( 20 ) character set utf8 collate utf8_general_ci null default null comment '姓名'
删除字段
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 null comment '姓名'");
以上就是通俗易懂讲解mysql数据库的增删改查的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product