测试中基础sql语句应用实例一:增删改

-“熟悉数据库就是会增删改查吗?”
-“还应包括:多表关联查询、分组查询、统计查询、常用函数、运维技巧。”

目前的测试工作中,基础 sql语句的使用较频繁,粗略总结增删改的应用。

一、功能点:同步数据源

《测试中基础sql语句应用实例一:增删改》 功能点UI

二、测试需求分析

《测试中基础sql语句应用实例一:增删改》 梳理测试点

三、测试用例中使用到的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;

    原文作者:Joey_GZ
    原文地址: https://www.jianshu.com/p/7060e2d5cd88
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞