mysql常用語法

2021-10-24 19:17:36 字數 1679 閱讀 5212

1.建立資料庫

create database 資料庫名;

2.刪除資料庫

drop database 資料庫名;

3.建立表

create table 表名;

4.刪除表

drop table 表名;

5.插入資料

insert into 表名 (列名1,列名2)values (value1,value2);

6.查詢資料

select 列名 from 表名 where 查詢條件 and(多個查詢條件)or(或者)查詢條件2;

7.更改資料

update 表名 set 列名1=new-value,列名2=new-value where 條件;

8.刪除資料

delete from 表名 where 條件

9.模糊查詢

select * from 表名 where 列名 like 『%條件』;

你可以在 where 子句中指定任何條件。

你可以在 where 子句中使用like子句。

你可以使用like子句代替等號 =。

like 通常與 % 一同使用,類似於乙個元字元的搜尋。

你可以使用 and 或者 or 指定乙個或多個條件。

你可以在 delete 或 update 命令中使用 where…like 子句來指定條件。

10.連線select語句

select * from 表名1 where 條件

union

select * from 表名2 where 條件;

11.排序

select * from 表名 where 條件 order by 排序條件 desc(公升序)asc(降序);

12.分組

select * from 表名 where 條件 group by 分組條件;(也可以用來去重)

13連線

select * from 表名1 a left join 表名2 b on a.id=b.id ;

14.是否為空

select * from 表名 where name is null;

select * from 表名 where name !=null;

15.索引

1.建立普通索引

create index 索引名 on 表名

2.修改表結構(新增索引)

alter table 表名 add index 索引名

3.建立表時指定

create table mytable(

id int not null,

username varchar(16) not null,

index [indexname] (username(length))

);4.刪除索引的語法

drop index 索引名 on 表名;

mysql常用語法 MySQL常用語法

更新資料 update 表名 set 健名 更改的值 where 建 刪除資料 delete from 表名 where 索引 create index 索引名稱 on 表名 鍵名 建立試圖 create view 檢視名 鍵,鍵 as select matchno,abs won lost fro...

mysql基本常用語法 mysql 常用語法

1.1.開啟 service mysql start 1.2.關閉 service mysql stop 1.3.重啟 service mysql restart 2.1.密碼明文 語法 mysql u使用者名稱 p使用者密碼 舉例 mysql uroot p123456 2.2.密碼密文 語法 m...

MY sql 常用語法

mysql show databases mysql create database mysqldata mysql use mysqldata mysql show tables 4 建立資料庫 bin mysql uroot p mysql create database mysqldata m...