案例講解 資料的增刪改

2021-08-20 19:53:56 字數 2146 閱讀 9420

#1.

執行以下指令碼建立表my_employees

use myemployees;

create table my_employees(

id int(10),

first_name varchar(10),

last_name varchar(10),

userid varchar(10),

salary double(10,2)

);create table users(

id int,

userid varchar(10),

department_id int

);#2.

顯示表my_employees的結構

desc my_employees;

#3.向my_employees表中插入下列資料

idfirst_name

last_name

userid

salary

1patel

ralph

rpatel

8952

dancs

betty

bdancs

8603

biri

benbbiri

1100

4newman

chad

cnewman

7505

ropeburn

audrey

aropebur

1550

#方式一:

insert into my_employees

values(1,'patel','ralph','rpatel',895),

(2,'dancs','betty','bdancs',860),

(3,'biri','ben','bbiri',1100),

(4,'newman','chad','cnewman',750),

(5,'ropeburn','audrey','aropebur',1550);

delete from my_employees;

#方式二:

insert into my_employees

select 1,'patel','ralph','rpatel',895 union

select 2,'dancs','betty','bdancs',860 union

select 3,'biri','ben','bbiri',1100 union

select 4,'newman','chad','cnewman',750 union

select 5,'ropeburn','audrey','aropebur',1550;

#4. 向users表中插入資料

1rpatel102

bdancs103

bbiri204

cnewman305

aropebur

40insert into users

values(1,'rpatel',10),

(2,'bdancs',10),

(3,'bbiri',20);

#5.將3號員工的last_name修改為「drelxer」

update my_employees set last_name='drelxer' where id = 3;

#6.將所有工資少於900的員工的工資修改為1000

update my_employees set salary=1000 where salary<900;

#7.將userid 為bbiri的user表和my_employees表的記錄全部刪除

delete u,e

from users u

join my_employees e on u.`userid`=e.`userid`

where u.`userid`='bbiri';

#8.刪除所有資料

delete from my_employees;

delete from users;

#9.檢查所作的修正

select * from my_employees;

select * from users;

#10.清空表my_employees

truncate table my_employees;

mysql資料的增刪改案例

直接po截圖和 mysql資料的增刪改案例 use myemployees 1.執行以下指令碼建立表my employees create table my employees id int 10 first name varchar 10 last name varchar 10 userid v...

游標簡單案例 增刪改

表 create table sp id int primary key identity,name varchar 50 商品名稱 price int,gz varchar 50 關注度 建立儲存過程 gocreate proc v add asbegin 建立游標 declare adds cu...

MongoDB增刪改查的案例

首先我們需要注入一下mongotemplate 模板 autowired private mongotemplate mongotemplate 最常見的用法還是接受乙個 query 物件作為引數進行查詢 修改 刪除的操作。這裡簡單介紹一些 query 和 criteria 的語法 where對應的...