mysql基本查詢語句

2021-09-25 23:52:28 字數 2220 閱讀 8050

資料庫操作的sql語句

show database

create database 資料庫名 charset=utf8

use 資料庫名

select database();

drop database 資料庫名

表結構操作的sql語句

show tables;

create table students(

id int unsigned primary key auto_increment not null,

name varchar(20) not null,

age tinyint unsigned default 0,

height decimal(5,2),

gender enum('男','⼥','⼈妖','保密')

);

alter table 表名 add 列名 型別 約束;

alter table 表名 modify 列名 型別 約束

alter table 表名 change 原名 新名 型別及約束;

alter table 表名 drop 列名;

show create table 表名;

show create database 資料庫名;

drop table 表名;

- 表資料操作的sql語句

– 1. 查詢所有列 select * from 表名;

例: select * from students; –

2. 查詢指定列 select 列1,列2,… from 表名;

3. 例: select id,name from students;

– 1. 全列插⼊:值的順序與表結構欄位的順序完全⼀⼀對應

insert into 表名 values (…)

例:insert into students values(0, 『xx』, default, default, 『男』);

– 2. 部分列插⼊:值的順序與給出的列順序對應

insert into 表名 (列1,…) values(值1,…)

例:insert into students(name, age) values(『王⼆⼩』, 15);

– 3. 全列多⾏插⼊

insert into 表名 values(…),(…)…;

例:insert into students values(0, 『張⻜』, 55, 1.75, 『男』),(0, 『關⽻』, 58, 1.85, 『男』

);– 4. 部分列多⾏插⼊

insert into 表名(列1,…) values(值1,…),(值1,…)…;

例:insert into students(name, height) values(『劉備』, 1.75),(『曹操』, 1.6);

delete from 表名 where 條件

例:delete from students where id=5;

上面的操作稱之為物理刪除,一旦刪除就不容易恢復,我們可以使用邏輯刪除的方式來解決這個問題。邏輯刪除,本質就是修改操作。

– 新增刪除表⽰字段,0表⽰未刪除 1表⽰刪除

alter table students add isdelete bit default 0;

– 邏輯刪除資料

update students set isdelete = 1 where id = 8;

Mysql 增減查詢基本語句

mysql增刪改查語句 select from insert into values update set xx xx where and delete from where xx and or mysql基本語句 增刪改查,like語句 查詢 select 欄位名 from 表名 例1 selec...

mysql基本語句 mysql基本語句

mysql關係型資料庫rds中的老大哥,增刪改查是mysql入門的基礎 增刪改查語句 增刪改查的語句命令為 增 insert 刪 delete 改 update 查 select或者show 庫操作建立資料庫 create database shujukuba 建立帶字符集的資料庫 create d...

MySQL基本多表查詢語句

所謂的多表查詢就是同時查詢多張表才能得到需要的資料 1.簡要概述 將乙個查詢結果作為另乙個查詢語句的一部分 select from employee where salary select max salary from employee 子查詢需要放在 中先執行子查詢,將子查詢的結果作為父查詢的一...