English 中文(简体)
SQl 插入问题后
原标题:SQl trigger after insert issue

我正在使用2005年SQ服务器进行触发工作。 我有一份更新后的表格。 在宣布变数后,该法典就是这样。

if @isconfirmed_before = 0 and @isconfirmed_after = 1
begin

if @invite_userid <>   
        begin

            select @points = points from dbo.InvitePoint where code =  USR  and packageid = @packageid
            INSERT INTO InviteCount
                   ([userID]
                   ,[joinMerchantID]
                   ,[packageID]
                   ,[points]
                   ,[joinDate])
             VALUES
                   (@invite_userid
                   ,@merchantid
                   ,@packageid
                   ,@points
                   ,getdate())
        end

 SET @alpha_numeric=  
        SELECT @alpha_numeric=@alpha_numeric+CHAR(n) FROM
        (
            SELECT TOP 8 number AS n FROM master..spt_values
            WHERE TYPE= p  and (number between 48 and 57 or number between 65 and 90)
            ORDER BY NEWID()
        ) AS t 

        update merchant
        set reg_code = @alpha_numeric
        where merchantid = @merchantid

END

第一部分

    update merchant  
    set reg_code = @alpha_numeric
    where merchantid = @merchantid

只有在插入行文时,才能插入这一条码,但每当表格有更新时,它都会发生变化。 如何做到这一点。 请帮助我,事先感谢你!

最佳回答
update merchant   
set reg_code = @alpha_numeric 
where merchantid = @merchantid 

该守则每当有更新时就执行,因为你没有有条件的流通阻止它有时执行。 如果你只想执行某些条件,你就不必在>条码/代码>栏中加以总结。

您说:“这部法规只有在插入一行时才能插入,但每当表格有更新时,它就会发生变化。” 为什么在<代码>中。 AFTER UPDATEstart 然后? 它希望列入<条码>。 AFTER INSERTstart. 除非我误解你。

问题回答

你们与触发点非常麻烦。 首先,你需要展示实际的触发代码。 我怀疑,你没有正确地把火烧掉。

接下来,你需要假设,触发器必须能够处理多个记录。 无论你为触发点的微量变量设定价值,你都可能做错事。 这可能不是因为你没有显示你如何获得可变的价值观而引发的。





相关问题
SQL Server database is not visible

I have installed ASP.NET application with database on our server. ASP.NET application created database using connection string below. The problem is that I do not see database in SQL Server Management ...

Most efficient way to store number 11.111 in SQL Server

What datatype is the most efficient to store a number such as 11.111. The numbers will have up 2 digits before the point and up to three after. Currently the column is a bigint , I am guessing that ...

表格和数据表

是否需要在提瓜表之后更新表格统计数据,还是自动更新?

Inconsistent Generate Change Script

I add a column of type tinyint and being set to not allow nulls in a table and generate the change scripts. The table has data in it at this time. The script has code that creates a temp table and ...

Performance of Sql subqueriesfunctions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have ...

selecting one value out of an xml column

I have a particularly troublesome xml column to query data from. The schema is fixed by the Quebec Ministry of Revenue so "it is what it is" The important part of the query looks like this: with ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签