创建表:create table myfirsttable (id int(4) primary key not null auto_increment,name char(20) not null default “Haha”,age int(4) not null default 18);
查询数据库下的全部表名:show tables;
查看表的结构:desc myfirsttable;(或使用:show columns from myfirsttable;)
在表中添加一列(字段) 属性:alter table myfirsttable column nick varchar(10) not null;
修改表名:alter table account rename Account;
修改列(字段) 的名字(但是要列的属性要重新更改): alter table myfirsttable change nick nickname int(5);
在表中修改一列(字段) 属性:alter table myfirsttable modify nickname varchar(10);
在表中删除一列(字段) alter table myfirsttable drop column nickname;
插入数据:insert myfirsttable (name ,age) values (“Aaaa”,19);
插入时如果手动输入id,如果输入的id数据库中没有,可以被出入进去。但是此条数据将在数据库中空缺的最上边的位置。
含有id的插入:insert myfirsttable (id,name,age) values(8,”Haha”,14);
删除一行记录:delete from myfirsttable where id=1;
多行删除(降序):delete from Account where password=”asd” order by id desc limit 3;
降序desc,升序asc。 命令含义:从Account表中,选出前3个(limit 3),password=字符串asd通过id进行降序排列后的数据进行删除。
