Home > Database > SQL > What are the basic database operation statements?

What are the basic database operation statements?

coldplay.xixi
Release: 2020-06-15 14:05:11
Original
13905 people have browsed it

What are the basic database operation statements?

数据库基本操作语句有哪些?

数据库基本操作语句有:

1 关于数据库的基本操作

SHOW DATABASES;  //查询数据库SHOW 
CREATE DATABASE score; //查询数据库的结构CREATE 
DATABASE score DEFAULT CHARSET utf8; //创建数据库
USE score;  //使用score数据库
DROP DATABASE score;  //删除数据库
Copy after login

2 关于表的操作

SHOW TABLES;      //显示数据库中的表CREATE TABLE score(
sno INT PRIMARY KEY AUTO_INCREMENT,
course VARCHAR(20),
sscore SMALLINT);   //创建表SHOW CREATE TABLE score;   //显示构造表语句DESC score;   //显示表结
ALTER TABLE score
ADD startTime DATE NOT NULL;   //添加字段ALTER TABLE score
DROP startTime;   //删除字段ALTER TABLE score
MODIFY course VARCHAR(50);   //修改字段类型ALTER TABLE score
CHANGE startTime endTime DATE;   //修改字段名DROP TABLE score;  //删除表
Copy after login

3 管理数据

INSERT INTO score(course,sscore)
VALUES('语文',80);   //添加数据UPDATE score
SET sscore=90WHERE sno=1;    //修改数据DELETE FROM score
WHERE sno=1;   //删除数据
Copy after login

4 查询数据

SELECT * FROM score;   //查询所有字段数据
Copy after login

去重:select distinct 字段 from 表名 where 条件

逻辑条件: and or

比较条件:< , <=, >, >=, <>, between value1 and value2

判断空:

  1)判断null: is null

  2)判断空字符串: ="" / <>""

模糊条件:like

  %:替换任意长度字符

  _:替换单个字符

分页查询,limit 起始行,查询行数

排序:order by 字段 asc/desc

  asc:升序

  desc:降序

分组:group by 字段

5 数据库中编码查询

SHOW VARIABLES LIKE &#39;character%&#39;;
Copy after login
Variable_name    Value
character_set_client    utf8
character_set_connection    utf8
character_set_database    utf8
character_set_filesystem    binary
character_set_results    utf8
character_set_server    utf8
character_set_system    utf8
character_sets_dir    C:\\Program Files\\MySQL\\MySQL Server 5.7\\share\\charsets\\
Copy after login

如果在查询过程中出现乱码,可以通过设置相应的字符编码解决。

比如在cmd客户端进行查询时,数据库中可能有中文,数据库character_set_client 设置的编码是utf8,而cmd解释是用gbk进行解释。所以会有乱码,设置character_set_client 编码为gbk即可。

SET character_set_client=&#39;gbk&#39;;
Copy after login

 推荐教程:《sql视频教程

The above is the detailed content of What are the basic database operation statements?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template