我在数据库中有一张 Country 表,其中包含以下字段
- 国家/地区
- 国家名称
现在我必须编写一个程序来首先检查@CountryName 是否存在。如果它已经存在,它应该更新该行。如果它不存在,它应该执行插入操作...
最佳答案
Create Proc [ProcedureName]
@CountryName nvarchar(100)
As
Begin
Declare @Count int
Set @Count = (Select count(CountryId) from Country where CountryName = @CountryName)
if @Count > 0
Begin
-- update
End
else
begin
-- insert
end
End
关于mysql - 在一个过程中执行插入和更新操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31692652/