在游标中创建用于插入,选择,更新和删除的过程

时间:2015-09-15 06:15:43

标签: sql-server insert cursor sql-delete procedure

我有一个问题,希望你能帮帮我 我想在游标中创建插入,选择,更新和删除的过程。 我创建了选择语法,为我做了什么? 我定义了这个,以便用户在此光标后运行select来显示它们的结果:

struct Product {
    let price: Price?

    init(dictionary: Dictionary<String, AnyObject>) {
        if let tmp = dictionary["price"] as? Dictionary<String, AnyObject> {
            price = Price(dictionary: tmp)
        }
        else {
            price = nil
        }
    }

    struct Price {
        let value : String

        init?(dictionary: Dictionary<String, AnyObject>) {
            if let xForY = dictionary["xForY"] as? Array<Int> where xForY.count == 2 {
                value = "\(xForY[0]) for \(xForY[1])"
            }
            else if let xForPrice = dictionary["xForPrice"] as? Array<Int> where xForPrice.count == 2 {
                value = "\(xForPrice[0]) / \(xForPrice[1]):-"
            }
            else if let reduced = dictionary["reduced"] as? String {
                value = "\(reduced):-"
            }
            else {
                return nil
            }
        }
    }
}

用户可以编写此代码来运行结果:

DECLARE TableCursor CURSOR GLOBAL
FOR
     SELECT TABLE_SCHEMA,TABLE_NAME
     FROM INFORMATION_SCHEMA.TABLES 
OPEN TableCursor
DECLARE @Name NVARCHAR(50)
DECLARE @Schema NVARCHAR(50)
FETCH NEXT 
FROM TableCursor 
INTO @Schema,@Name 
WHILE @@FETCH_STATUS = 0 
BEGIN   
      EXECUTE('         
               CREATE PROC USP_SEL_'+@Schema+'_'+@Name+'        
               AS       
               BEGIN            
                     SELECT *
                     FROM '+@Schema+'.'+@Name+'         
               END
             ')
      FETCH NEXT        
      FROM TableCursor      
      INTO @Schema,@Name 
END 
CLOSE TableCursor 
DEALLOCATE TableCursor

我的问题是,对于他们刚刚编写EXEC [dbo].[USP_SEL_Production_Product] 并查看其结果的用户,我可以为插入,更新和删除做些什么?

0 个答案:

没有答案