2013-09-23 77 views
-2

我有3個表:我想更新現有記錄我該怎麼辦?

CREATE TABLE employee(
presismail varchar(50) NOT NULL, 
name varchar (50), 
lastname varchar (50), 
CONSTRAINT presismail PRIMARY KEY (presismail)) 

CREATE TABLE users(
usermail varchar(50)NOT NULL, 
nomail varchar (2), 
CONSTRAINT usermail PRIMARY KEY (usermail)) 


CREATE TABLE assignment(
presismail varchar(50)NOT NULL, 
usermail varchar(50)NOT NULL, 
senddates varchar (20)NOT NULL, 
answervalue varchar (3), 
receivedates varchar (20) 
CONSTRAINT PK_assignment PRIMARY KEY (presismail, usermail, senddates), 
FOREIGN KEY (presismail) REFERENCES employee(presismail), 
FOREIGN KEY (usermail) REFERENCES users(usermail)) 

我想創建一個StoredProcedure的,增加值到已選定2列。

insert into assignment(answervalue, receivedates) 
values (@answervalue, @receivedates) 
select answervalue, receivedates 
from assignment 
where presismail = @presismail 
and usermail = @usermail 
and senddates = @senddates 

我該怎麼做?

+0

你的問題不清楚,你可以給樣品記錄嗎? –

+0

您正在使用哪些DBMS? –

回答

1

我想你想更新現有的記錄,

UPDATE assignment 
SET answervalue = @answervalue, 
     receivedates = @receivedates 
WHERE presismail = @presismail 
     AND usermail = @usermail 
     AND senddates = @senddates 
+0

完美!正是我想要的:)也許我描述它很差:/ –

+0

你可以簡單地修改你的問題,並要求你想更新現有的記錄。 –

1

試試這個。

insert into assignment(answervalue, receivedates) 
select answervalue, receivedates 
from assignment 
where -------- 
相關問題