1. 程式人生 > >測試用到的基礎sql語句

測試用到的基礎sql語句

SQL
測試常用語句:
sp_help tablename查看下錶結構
(1)插入
insert into tablename (‘004’,‘楠楠’,24,‘天津’)
順序不可亂。如果插入失敗,則全部插不進去
不插入的欄位預設為空null
格式:
insert into 表名(欄位1,欄位2) values (‘啦啦’,12)
(2)刪除
delete from tables where 匹配條件;
原理:逐行掃描,當滿足條件,即操作
(3)更新
改一個數據:
update worker set salary =salary+1000 where id =17372823383298476654;
改多個數據:
update worker set salary =salary+30,phone=13910281675 where id =17372823383298476654;
(4)查詢
select id,state from where name =‘zz’;
等於號=還可以替換成 >大於 , !>不大於 , 不等於!=,不等於<>
like模糊匹配
其他:
(1)單行註釋 –
(2)
/*
多行註釋:實現testing資料庫存在,則刪除再建立
*/
例子
if exists(
selectname from database where name =‘testing’;
)
drop database testing;
go
create database testing;
go