我想更新现有记录我该怎么办?

时间:2013-09-23 12:34:03

标签: sql

我有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))

我想创建一个存储过程,将值添加到已选择的2列中。

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

我该怎么做?

2 个答案:

答案 0 :(得分:1)

我认为你想要更新现有记录,

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

答案 1 :(得分:1)

试试这个。

insert into assignment(answervalue, receivedates) 
select answervalue, receivedates 
from assignment 
where --------