mysql資料庫操作的基本語句

2021-12-30 07:39:25 字數 1682 閱讀 7066

1. 運算元據庫

create database score default charset utf8; //建立資料庫

use score; //使用score資料庫

show databases; //查詢資料庫

drop database score; //刪除資料庫

show create database score; //查詢資料庫的結構2. 操作表

create table score(

id int primary key auto_increment,

username varchar(20),

sscore smallint); //建立表

drop table score; //刪除表

show tables; //顯示資料庫中的表

alter table score

add starttime date not null; //新增字段(列)

alter table score

drop starttime; //刪除字段(列)

alter table score rename newscore; //修改表名

alter table score

change starttime endtime date; //修改欄位名

alter table score

modify course varchar(50); //修改字段型別

desc score;   //顯示表結構

show create table score; //顯示構造表語句3.運算元據

insert into score(course,sscore)

values('語文',80); //新增資料

delete from score

where sno=1; //刪除資料

update score

set sscore=90

where sno=1; //修改資料

select * from score; //查詢所有字段資料查詢資料細化:

去重: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 欄位4. 資料庫編碼

如果在查詢過程**現亂碼,可以通過設定相應的字元編碼解決。

比如在cmd客戶端進行查詢時,資料庫中可能有中文,資料庫character_set_client 設定的編碼是utf8,而cmd解釋是用gbk進行解釋。所以會有亂碼,設定character_set_client 編碼為gbk即可。

解決亂碼:

set character_set_client='gbk';

mysql資料庫基本操作語句

1 更改欄位名 change alter table student change column gradenews grade int 11 2 增加欄位和刪除字段 alter table student add column salary int 30 default 900000 alter ...

MySQL對資料庫的基本操作語句

前言 學習sql server已經兩年了,在學的時候覺得還不錯,但是在這接近兩年的時候中對於資料庫的操作大多只是簡單的增刪改查,很多東西都慢慢遺忘了,因為現在需要使用mysql,所以就再對sql進行乙個學習,並將其學習經歷記錄下來 建立資料庫 create database db name 建立資料...

MYSQL資料庫基本語句

sqlite3支援的型別 整數,文字,浮點,二進位制 sqlite3 test.sqlite test.sqlite是資料庫的名字 table 檢視資料庫中是否有表 建立表 no學號 整型 主鍵 自動增長的 不能為空 name姓名 文字 不能為空 age年齡 整型 create table stud...