mysql 部分语句记录
如表: user
字段: userid name pw
本来user表的useid不是自增的。 我们把userid改为自增。
执行以下语句就可以把userid自增, 每次加1。
语句:alter table `user` change userid userid int not null auto_increment primary key;
//移动
alter table 表名 modify 字段名 字段类型 after 字段
举例
alter table user_info modify user_name varchar(10) after user_id;
将user_name字段移到user_id后面
如果想移到最前面:
alter table user_info modify user_id char(8) first;//将user_id移到最前面!!
truncate table 表名; //清空数据
alter table `j_new` change id id int not null auto_increment;//修改表 j_new 主键ID为自增
create table j_user(username varchar(20),password varchar(20));//创建 j_user 名字的表
create table j_service(id int(4) primary key not null auto_increment,title varchar(50) not null, content longtext); //创建 j_service 表 设置ID为主键并且自增
//循环
create procedure pro10()
begin
declare i int;
set i=0;
while i<10 do
insert into j_product(title,images,content) values ('苹果手机','1.jpg','内容');
set i=i+1;
end while;
end;//
call pro10() //调用
desc 表名;//查询表的字段类型
背景:
输入一串查询语句,以分号结束,发现没有结束,再打回车,分号,还是不完。
什么exit,quit,bye,都不顶用
如果要ctrl+C吧,又得退出mysql,一切重来,很麻烦。
后来终于发现,引起这种现象的原因是sql语句有问题,这次遇到的是引号不成对的问题。
解决:
加一个 ';(单引号和分号),即可执行sql,然后,你就好好检查sql是哪里有问题了吧

浙公网安备 33010602011771号