如何使用存储过程更新所有记录 [英] how to update all records using stored procedure

查看:91
本文介绍了如何使用存储过程更新所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请一些人告诉我如何更新存储过程中的所有记录,就像我有一个名为employee的表。并且该表中的列是empid,gender。在性别列中,存储的数据是男性和女性。我需要编写存储过程来更新所有recoreds,其中gender = male替换为性别=女性。



基本上将女性记录更新为男性。



请帮我解决问题。

解决方案

我不知道为什么你需要这样做但是给出了你说你想这样做。

你不一定需要存储过程。进行更新的T-SQL是:



UPDATE员工SET gender =''male''WHERE gender =''female''



你可以根据需要创建一个SP:



  CREATE   PROCEDURE  UpdateGenders 
AS
BEGIN
更新员工 SET gender = < span class =code-string>' male' WHERE gender = ' female'
END


pls some one tell that how to update all records in stored procedure like i have a table called employee. and the column in that table are empid, gender. in gender column the stored data is male and female both. i need to write the stored procedure to update all recoreds where gender=male to replace like gender=female.

basically update female records to male.

Pls help me to solve the problem.

解决方案

I''m not sure why you need to do this but given you say you want to do this.
You don''t necessarily need a stored procedure. The T-SQL to do the update is:

UPDATE employee SET gender =''male'' WHERE gender = ''female''

You can create a SP if you want:

CREATE PROCEDURE UpdateGenders
AS
BEGIN
    UPDATE employee SET gender ='male' WHERE gender = 'female'
    END


这篇关于如何使用存储过程更新所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆