在SQL上操作MySQL基本操作

in blog •  6 years ago  (edited)

创建一个数据库:create database hashaki;

显示数据库:show databases;

前往某个数据库:use hashaki;

显示该数据库下的表:show tables;

JJU是名字,somedate是日期,sal是数据

创建一个表:create table JJ(JJU varchar(10),somedate date,sal decimal(10,2),deptbo int(2));

显示表:desc JJ;

查看更多的表信息:show create table JJ; 或者:show create table JJ \G(这个排版会好看点)

修改表,比如修改JJ的JJU的varchar(10)->varchar(20):alter table JJ modify JJU varchar(20);

表中增加字段age:alter table JJ add column age int(3);

字段改名:alter table JJ change JJU jj int(4); JJU是JJ里面的一个varchar(20)类型,名字改成jj类型改成int(4)

插入字段到某个字段后:alter table JJ add YPL date after jj; YPL是新创建的字段,放在字段jj的后面

把某个字段放在第一位:alter table JJ modify YPL date first;

表改名:alter table JJ rename ypl;

修改字段变量:insert into JJ(YPL,jj,somedate,deptbo,age) values('2009-01-20',810,'2018-08-26',1,24);
:insert into JJ values('1994-08-10',520,'1994-08-14',13,14); 这是简便形式,但参数要对齐
:insert into JJ(deptbo,age) values(666,777);

2.jpg

3.jpg

4.jpg

更新数据:update JJ set deptbo=24 where YPL='2009-01-20';
2.jpg

查询:select * from JJ *表示显示所有数据,但是要查询某部分字段就要列名字出来

查询某部分:select YPL,age from JJ;

带条件查询:select YPL,age from JJ where jj=520;
:select YPL,age from JJ where jj=520 and deptbo<20;

排序:select * from JJ order by jj; 升序排序

限制:select * from JJ order by jj limit 2; 只出现前2个数据
: select * from JJ order by jj limit 1,3; 从第二条数据开始,只显示3条数据

删除记录:delete from JJ where age=777;

删除表中字段:alter table JJ drop column age;

删除数据库:drop database name;

删除表:drop table name;

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!