測試中基礎sql語句應用實例一:增刪改

-“熟悉數據庫就是會增刪改查嗎?”
-“還應包括:多表關聯查詢、分組查詢、統計查詢、常用函數、運維技巧?!?/p>

目前的測試工作中,基礎 sql語句的使用較頻繁,粗略總結增刪改的應用。

一、功能點:同步數據源
功能點UI
二、測試需求分析
梳理測試點
三、測試用例中使用到的sql語句

== 表 ==
【新建表】

create table t333(
    id int not null default 0 primary key,
    department varchar(40) not null default ' '
); --mysql建表
create table table1(
    id varchar2(40) not null,
    username varchar2(40) not null,
    constraint database_table1 primary key (id)  
); --oracle建表

【修改表名】

alter table test rename test1;

【拷貝表、備份表】

--Method 1:
create table t333_copy like t333;   
insert into t333_copy select * from t333;
--Method 2:
create table t333_copy as select * from t333;

【插入多行表記錄】

insert into table1 values ('I1','Ada'),
                          ('I2','Beta'),
                          ('I3','Cate');

【修改表名】

rename table1 to table2;

【刪除表】

drop table t333;

== 字段 ==

【添加字段】

--添加字段phone
alter table t333 add phone varchar(60) not null; ```


【修改字段名】

--Method 1:
alter table t333 change column phone phone333 varchar(60) not null;

--Method 2:
alter table t333 rename column phone to phone333;


【修改字段類型、長度】

--Step 1:
alter table t333 modify column phone333 char(30) not null;

--Step 2:
alter語句運行完畢,在查詢界面,選中表t333使用快捷鍵 [ctrl+d ],顯示表結構

【修改字段數據】

update t333 set department='dpmtA' where id=3;

【刪除字段】

alter table t333 drop column phone333;

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容