優化判斷資料是否存在

2021-10-09 03:20:18 字數 606 閱讀 3115

select

count(*

)from

table

where a =

1and b =

2//常見寫法 這樣還會把整張表查完看是否還存在

int nums = xxdao.

count***xby***

(params);if

( nums >0)

else

select

1from

table

where a =

1and b =

2limit

1//常見寫法 這樣還會把整張表查完看是否還存在

integer exist = xxdao.

exist***xby***

(params);if

( exist != null )

else

sql不再使用count,而是改用limit 1,讓資料庫查詢時遇到一條就返回,不要再繼續查詢還有多少條了

業務**中直接判斷是否非空即可

SQL判斷是否存在

判斷資料庫是否存在 if exists select from master.sysdatabases where name n 庫名 print exists else print not exists 判斷要建立的表名是否存在 if exists select from dbo.sysobjec...

SQL判斷是否存在

1 判斷資料庫是否存在 2 ifexists select frommaster.sysdatabaseswherename n 庫名 3print exists 4 else 5print notexists 67 8 判斷要建立的表名是否存在 9 ifexists select fromdbo....

判斷檔案是否存在

c 判斷檔案是否存在 int access const char filename,int amode 函式用法 寬位元組int waccess const char filename,int amode c 判斷檔案是否存在 標頭檔案 access const char filename,int ...