zoukankan      html  css  js  c++  java
  • 游标

    --select * from master..sysprocesses
    --use test
    declare my_cursor cursor scroll dynamic --scroll表示可以向前或向后移动 dynamic:表示可写也可读,
    for
    SELECT DaoHangMingCheng,DaoHangKey,YeMianMingCheng,KeyString AS YeMianKey FROM dbo.YeMianT --定义my_cursor 游标
    open my_cursor --打开游标
    declare @DaoHangMingCheng nvarchar(128)--定义一个变量
    declare @DaoHangKey varchar(128)--定义一个变量
    declare @YeMianMingCheng nvarchar(128)--定义一个变量
    declare @YeMianKey varchar(128)--定义一个变量


    fetch next from my_cursor into @DaoHangMingCheng,@DaoHangKey,@YeMianMingCheng,@YeMianKey --游标停在第一条记录前面,第一次执行,测试有没有记录存在

    while(@@fetch_status=0) --取数据,直到-2即没有记录
    begin


    INSERT INTO [Tangniaobing].[dbo].[GongNengLieBiaoT]
    ([CreatedTime]
    ,[KeyString]
    ,[GongNengMingCheng]
    ,[DaoHangMingCheng]
    ,[DaoHangKey]
    ,[YeMianMingCheng]
    ,[YeMianKey]
    ,[GongNengZiFu])
    VALUES(
    GETDATE(),
    NEWID(),
    'Select',
    @DaoHangMingCheng,
    @DaoHangKey,
    @YeMianMingCheng,
    @YeMianKey,
    '')


    INSERT INTO [Tangniaobing].[dbo].[GongNengLieBiaoT]
    ([CreatedTime]
    ,[KeyString]
    ,[GongNengMingCheng]
    ,[DaoHangMingCheng]
    ,[DaoHangKey]
    ,[YeMianMingCheng]
    ,[YeMianKey]
    ,[GongNengZiFu])
    VALUES(
    GETDATE(),
    NEWID(),
    'Add',
    @DaoHangMingCheng,
    @DaoHangKey,
    @YeMianMingCheng,
    @YeMianKey,
    '')


    INSERT INTO [Tangniaobing].[dbo].[GongNengLieBiaoT]
    ([CreatedTime]
    ,[KeyString]
    ,[GongNengMingCheng]
    ,[DaoHangMingCheng]
    ,[DaoHangKey]
    ,[YeMianMingCheng]
    ,[YeMianKey]
    ,[GongNengZiFu])
    VALUES(
    GETDATE(),
    NEWID(),
    'Delete',
    @DaoHangMingCheng,
    @DaoHangKey,
    @YeMianMingCheng,
    @YeMianKey,
    '')


    INSERT INTO [Tangniaobing].[dbo].[GongNengLieBiaoT]
    ([CreatedTime]
    ,[KeyString]
    ,[GongNengMingCheng]
    ,[DaoHangMingCheng]
    ,[DaoHangKey]
    ,[YeMianMingCheng]
    ,[YeMianKey]
    ,[GongNengZiFu])
    VALUES(
    GETDATE(),
    NEWID(),
    'Update',
    @DaoHangMingCheng,
    @DaoHangKey,
    @YeMianMingCheng,
    @YeMianKey,
    '')


    --fetch next from my_cursor
    fetch next from my_cursor into @DaoHangMingCheng,@DaoHangKey,@YeMianMingCheng,@YeMianKey
    end

    close my_cursor
    deallocate my_cursor
    --SELECT * FROM [GongNengLieBiaoT]

  • 相关阅读:
    SHELL
    Docker
    RHCE内容记要
    mysql基本知识的总结
    Linux启动提示Kernel panic
    配置tomcat、nginx实现反向代理(需操作)
    linux下nginx的安装和配置
    linux下安装mysql5.7(centos6.0)
    linux打包解压包(.tar .gz .tar.gz .zip)
    多重继承下的类型转换
  • 原文地址:https://www.cnblogs.com/rhws/p/4252441.html
Copyright © 2011-2022 走看看