Mysql入门语句

来源:互联网 发布:淘宝店铺介绍大全 编辑:程序博客网 时间:2024/05/17 19:16

创建一个数据库:

create database 数据库名;

查看已经创建了哪些数据库:

show databases;

选择索要操作的数据库:

要对一个数据库进行操作,必须先选择该数据库,否则会提示错误:
ERROR 1046(3D000): No database selected

创建数据库表:

create table 表名称(列声明):
例如:create table students(id int,name char(8),sex char(4),age tinyint);

向表中插入数据:

inser [into] 表名称 [(列表1,列表2,列表3,。。。)] values (值1,值2,值3,。。。);
只需要向表中插入部分数据,或者不按顺序插入,可以使用into插入:
insert into student (name,sex,age) values (“昊建”,“男”,18);

查询表中数据:

select 列名称 from 表名称 [查询条件];

也可以使用通配符*查询表中所有内容:

select * from students;

按特定条件查询:

where 关键词用于指定查询条件, 用法形式为: select 列名称 from 表名称 where 条件;
条件例如 =、>、<、>=、<、!= 以及一些扩展运算符 is [not] null、in、like 等等。
 

更新表中数据:

update 表名称 set 列名称=新值 where 更新条件;

删除表中的数据:

delete from 表名称 where 删除条件;

创建表后的修改:

alter table 语句用于创建后对表的修改,基础语法如下:

添加列:

alter table 表名 add 列名 列数据类型 [after插入的位置];

修改列:

alter table 表名 change 列名称 列新名称 新数据类型;

删除列:

alter table 表名 drop 列名称;

重命名:

alter table 表名 rename 新表名;

删除整张表:

drop table 表名;

删除整个数据库:

drop database 数据库名;
0 0
原创粉丝点击