1

我有一个将数据插入表的过程。我将要插入表(输入参数)的值声明为 Varchar 类型。但是表中 2 列的列类型已更改为 Int 类型。但程序仍在正确插入值。(基础表 IssuerGroupIDMapping 中的 IssuerId 和 Employer Id 列是 int 类型。)对我来说重要的问题是该程序在某些特定情况下会失败,我已经在 C# 中检查,以便只传递有效的整数进行。我需要立即更改代码吗?(对我来说有点问题,因为程序已经在生产中并且似乎正在运行。)。请建议。

以下是我的程序代码:

CREATE PROCEDURE [uspInsertIssuerGroupIDMapping]
@EmployerID Varchar(25),    
@IssuerID Varchar(25),  
@PlanID Varchar(25),    
@IssuerGroupID Varchar(25), 
@CreateUserID Varchar(25)

*****/
AS

BEGIN TRY

    SET NOCOUNT ON
    SET XACT_ABORT ON

    --check to see if a duplicate trigger exists
    IF ( NOT EXISTS (SELECT 1 FROM [IssuerGroupIDMapping] 
                             WHERE EmployerId = @EmployerID AND PlanId = @PlanID)
                    )

    BEGIN


        INSERT INTO [IssuerGroupIDMapping]
               ([EmployerId]
               ,[IssuerId]
               ,[PlanId]
               ,[IssuerGroupID]
               ,[CreateUserId]
               ,[CreateDate]
               ,[UpdateUserId]
               ,[UpdateDate]
               )
         VALUES
               ( 
                 @EmployerID
                ,@IssuerID
                ,@PlanID
                ,@IssuerGroupID
                ,@CreateUserId
                ,(SELECT Framework.udfGetTimeTravelDate())
                ,@CreateUserId
                ,(SELECT Framework.udfGetTimeTravelDate())
               );

               SELECT @@ROWCOUNT;
        END
        ELSE
        BEGIN
            --if a duplicate record exists update it
            UPDATE [IssuerGroupIDMapping] SET 
                                 IssuerId = @IssuerID
                                ,IssuerGroupID = @IssuerGroupID
                                ,UpdateDate = (SELECT Framework.udfGetTimeTravelDate())
                                ,UpdateUserId = @CreateUserID

            WHERE EmployerId = @EmployerID
                                    AND PlanId = @PlanID

            SELECT @@ROWCOUNT;

        END
4

2 回答 2

1
于 2013-09-27T14:07:18.920 回答
0

The biggest issue that you are going to run into with this conversion is performance. SQL can figure out what you're trying to do with implicit conversions. However, it will be unable to use indexing and statistics to their full advantage.

In a large dataset, which no database starts out as but successful ones usually grow into, you could run into major performance problems.

Read this excellent article by SQL Server expert Tibor Karaszi:

http://sqlblog.com/blogs/tibor_karaszi/archive/2009/04/28/match-those-types.aspx

于 2013-09-27T14:07:46.347 回答