MYSQL数据库基本操作语句
2017-10-13 15:43
363 查看
MYSQL为关系型数据库,所谓关系,即可以理解为表格的概念,一个关系型数据库由一个或者数个表格组成
表头header
行row
列col
值value
键key
数据库database
连接数据库:
mysql -host(主机名) -u(用户名) -p(登录密码,为空则忽略此项)
创建一个数据库
create database +数据库名(samp_db) 【其他选项】
createdatabase samp_db character set gbk
创建一个叫sanmp_db的数据库并设置编码为gbk
创建数据库表
create table +表名称(列声明)
creattable students (
id int unsigned not null auto_incrementprimary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default “-”
);
插入数据
insert [into] 表名 [(列名1,列名2,列名3,…)] values (值1,值2,值3,…);
insertinto students values(NULL,”王刚“,”男“,20,”17625612527“);
insertinto students (name,sex,age) values (“孙丽华”,“女“,21);
查找数据
select 列名称 from
表名称 [查询条件];
selectname,age from students;
按照特定的条件查找
select 列名称 from
表名称 where 条件;
select* from students where age > 21;
select* from students where name like “%王%”;
更新表中的数据
update 表名称 set 列名称=新值whiere 更新条件;
updatestudents set tel=default where id=5;
updatestudents set age=age+1;
删除表中的数据
deletefrom 表名称 where
删除条件;
delete f’rom students whereid=2;
创建后表的修改
添加列
alter table 表名 add
列名 列数据类型 【alert插入位置】
altertable students add birthday date after age;
修改列
alter table 表名 change列名称 列新名称 新数据类型;
altertable students change tel telphone char(13) default;
altertable students change name name char(16) not null;
删除列
alter table 表名 drop
列名称 ;
altertable students drop birthday;
重命名表
alter table 表名 re
823b
name
新表名;
alter table students rename workmates;
删除整张表
drop table 表名;
droptable workmates;
删除整个数据库
drop databases 数据库名称;
dropdatabases samp_db;
表头header
行row
列col
值value
键key
数据库database
连接数据库:
mysql -host(主机名) -u(用户名) -p(登录密码,为空则忽略此项)
创建一个数据库
create database +数据库名(samp_db) 【其他选项】
createdatabase samp_db character set gbk
创建一个叫sanmp_db的数据库并设置编码为gbk
创建数据库表
create table +表名称(列声明)
creattable students (
id int unsigned not null auto_incrementprimary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default “-”
);
插入数据
insert [into] 表名 [(列名1,列名2,列名3,…)] values (值1,值2,值3,…);
insertinto students values(NULL,”王刚“,”男“,20,”17625612527“);
insertinto students (name,sex,age) values (“孙丽华”,“女“,21);
查找数据
select 列名称 from
表名称 [查询条件];
selectname,age from students;
按照特定的条件查找
select 列名称 from
表名称 where 条件;
select* from students where age > 21;
select* from students where name like “%王%”;
更新表中的数据
update 表名称 set 列名称=新值whiere 更新条件;
updatestudents set tel=default where id=5;
updatestudents set age=age+1;
删除表中的数据
deletefrom 表名称 where
删除条件;
delete f’rom students whereid=2;
创建后表的修改
添加列
alter table 表名 add
列名 列数据类型 【alert插入位置】
altertable students add birthday date after age;
修改列
alter table 表名 change列名称 列新名称 新数据类型;
altertable students change tel telphone char(13) default;
altertable students change name name char(16) not null;
删除列
alter table 表名 drop
列名称 ;
altertable students drop birthday;
重命名表
alter table 表名 re
823b
name
新表名;
alter table students rename workmates;
删除整张表
drop table 表名;
droptable workmates;
删除整个数据库
drop databases 数据库名称;
dropdatabases samp_db;
相关文章推荐
- mysql数据库基本查询语句操作
- mysql数据库常用的基本SQL语句--数据库表操作
- mysql数据库的基本操作语句
- mysql数据库表的基本操作sql语句总结
- mysql数据库常用的基本SQL语句--数据库数据操作
- 通过sql语句对mysql数据库进行基本的操作
- mysql数据库的基本操作语句
- Linux下MySQL数据库常用基本操作 一
- MySQL数据库基本操作
- Linux下MySQL数据库常用基本操作
- PHP使用mysqli对mysql数据库的基本操作
- SQL 基本查询语句操作
- MYSQL数据库基本DDL语句
- php操作mysql数据库的连接语句以及最简单的增删改查语句
- 常用的Mysql数据库操作语句大全
- MySQL数据库表的基本操作——修改表ALTER TABLE,删除表
- MySQL数据库 基本操作命令
- Mysql的基本操作语句(适合初学者借鉴)
- oracle 基本操作三:DML语句,数据完整性之约束,约束的维护
- 【SQL Server 数据库基本语句操作】