zoukankan      html  css  js  c++  java
  • sql server 建临时表修改数据

    某种情况下,我们需要对数据库某个表的某些字段执行相同的修改,例如用户表存储的密码最初是以小写的形式进行存储的,如果我们需要将其全部转换为大写,以下t-sql语句可以解决此问题,原理是通过创建临时表来存储当前表的信息,再通过循环修改我们想要改变的密码字段:

    /********************MC_User即为用户信息表************************/

    declare @count int
    declare @index int
    declare @tmpID int
    declare @tmpUserPassword nvarchar(50)

    declare @tmpTable table
    (
     Inde int identity(1,1),
     ID int,
     UserPassword nvarchar(50)
    )

    insert into @tmpTable select a.ID,a.UserPassword from MC_User a

    set @count=@@ROWCOUNT
    set @index=1
    while @index<=@count
    begin
     select @tmpID= ID,@tmpUserPassword= UserPassword from @tmpTable where Inde=@index
     update MC_User set UserPassword=UPPER(@tmpUserPassword)
     where ID=@tmpID
     
     set @index=@index+1
    end

  • 相关阅读:
    this指针详解
    C++处理异常
    C++中的this指针
    c++中的string类
    c面试题总结
    c++中的引用详解
    c++中的new和delete
    函数重载
    BST(二叉排序树)的插入与删除
    ccf行车路线
  • 原文地址:https://www.cnblogs.com/shuzehui/p/1884890.html
Copyright © 2011-2022 走看看