我想如果這樣做存儲過程,如果記錄存在則更新
這裏來檢查,如果記錄存在,然後更新它是我目前有:(這顯然是行不通的)
CREATE PROCEDURE dbo.update_customer_m
@customer_id INT ,
@firstname VARCHAR(30) ,
@surname VARCHAR(30) ,
@gender VARCHAR(6) ,
@age INT ,
@address_1 VARCHAR(50) ,
@address_2 VARCHAR(50) ,
@city VARCHAR(50) ,
@phone VARCHAR(10) ,
@mobile VARCHAR(11) ,
@email VARCHAR(30) ,
AS
IF EXISTS
(
SELECT *
FROM dbo.Customer
WHERE CustID = @customer_id
)
BEGIN
UPDATE dbo.Customer
SET Firstname = @firstname, Surname = @surname, Age = @age, Gender = @gender, Address1 = @address_1, Address2 = @address_2, City = @city, Phone = @phone, Mobile = @mobile, Email = @email
WHERE CustID = @customer_id
END
有沒有更好的方式來做到這一點?
雖然這個工作,我的代碼是錯誤的,所以我會打開一個新的問題。不管怎樣,謝謝你。 – user2279712 2014-09-11 05:57:30