用SQL語句判斷資料庫中的記錄是否存在

2021-04-03 00:04:16 字數 733 閱讀 6342

alter procedure wg_news_insertcategory

@name  varchar(50),

@description varchar(250),

@imageurl varchar(250),

@categoryid int output

asdeclare @currid int

-- see if the category already exists

select @currid = categoryid

from news_categories

where name = @name

-- if not, add it

if @currid is null

begin

insert into news_categories

(name, description, imageurl)

values (@name, @description, @imageurl)

set @categoryid = @@identity

if @@error > 0

begin

raiserror ('insert of category failed', 16, 1)

return 99

endend

else

begin

set @categoryid = -1

end

刪除SQL資料庫中相同記錄的SQL語句

資料庫種馬 資料庫中很多表存在大量相同記錄 經高人指點刪除相同記錄 僅保留一個 的sql語句如下 declare tmptb table id int not null sortname nvarchar 100 collate chinese prc ci as null sortnote nva...

MySQL資料庫中,如何記錄SQL執行語句

原帖 開啟sql執行記錄功能 set global log output table 輸出到表 set global log on 開啟所有命令執行記錄功能general log,所有語句 成功和未成功的.set global log slow queries on 開啟慢查詢sql記錄slow l...

SQL語句查詢資料庫中重複記錄的個數

複製 如下 select a,b,c,count 程式設計客棧 fro程式設計客棧m select c.a,c.b,c.c from test www.cppcns.comh ing count 2 group by a,b,c 或者 複製 如下 select zdbh,tdzl,zdmj,coun...

使用SQL語句來判斷資料庫中時間,是否為當日時間

1.專案情景 這兩天寫功能時,有一條是使用者簽到,當天只能簽到一次。一直想的是將系統當前時間和資料庫中的最近時間進行比較。但具體怎麼處理資料庫中datatime型別的資料一直沒有頭緒。2.sql語句解決 select count 1 from sign detail where date forma...

轉 查詢前幾條記錄SQL在不同資料庫中的用法

查詢前幾條記錄sql在不同資料庫中的用法 1.oracle select from table1 where rownum n 2.informix select first n from table1 3.db2 select row number over order by col1 desc ...