我有一个将值插入表中的存储过程:
ALTER PROCEDURE [dbo].[spSaveAddresses_LegalDescriptions_Determinations]
@idAddresses_LegalDescriptions_Determinations INT = NULL OUTPUT,
@idLogin INT = -32768,
@idAddress INT = NULL,
@idLegalDescription INT = NULL,
@idDetermination INT = NULL
AS
SET NOCOUNT ON
SET ROWCOUNT 0
SET XACT_ABORT ON
BEGIN TRY
/* Declare and initialize variables */
DECLARE @RC INT,
@TranCount INT
SELECT
@RC = 0,
@TranCount = @@TRANCOUNT
/* Insert record into Table #1] */
IF @TranCount = 0
BEGIN TRANSACTION
BEGIN
INSERT INTO [TOD].[dbo].[Table#1](idAddress, idLegalDescription,
idDetermination, UpdatedidLogin,
UpdatedDate)
VALUES(@idAddress, @idLegalDescription,
@idDetermination, @idLegalDescription, GETDATE())
END
IF @TranCount = 0 AND (XACT_STATE()) = 1
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF (XACT_STATE()) = -1 ROLLBACK TRANSACTION
EXEC [TOD].[dbo].[spRethrowError]
SET @RC = 1
END CATCH
SET NOCOUNT OFF
SET ROWCOUNT 0
RETURN @RC
GO
表#1的结构:
CREATE TABLE [dbo].[Addresses_LegalDescriptions_Determinations]
(
[idAddresses_LegalDescriptions_Determinations] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[idAddress] [int] NULL,
[idLegalDescription] [int] NULL,
[idDetermination] [int] NULL,
[UpdatedidLogin] [smallint] NOT NULL
CONSTRAINT [DF_Addresses_LegalDescriptions_Determinations_UpdatedidLogin] DEFAULT ((0)),
[UpdatedDate] [datetime] NOT NULL,
CONSTRAINT [pkAddresses_LegalDescriptions_Determinations]
PRIMARY KEY CLUSTERED ([idAddresses_LegalDescriptions_Determinations] ASC)
) ON [DATA]
GO
ALTER TABLE [dbo].[Addresses_LegalDescriptions_Determinations] WITH NOCHECK
ADD CONSTRAINT [FK_Addresses_LegalDescriptions_Determinations_Addresses]
FOREIGN KEY([idAddress])
REFERENCES [dbo].[Addresses] ([idAddress])
ON DELETE CASCADE
NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[Addresses_LegalDescriptions_Determinations]
CHECK CONSTRAINT [FK_Addresses_LegalDescriptions_Determinations_Addresses]
GO
ALTER TABLE [dbo].[Addresses_LegalDescriptions_Determinations] WITH NOCHECK
ADD CONSTRAINT [FK_Addresses_LegalDescriptions_Determinations_Determinations]
FOREIGN KEY([idDetermination])
REFERENCES [dbo].[Determinations] ([idDetermination])
ON DELETE CASCADE
NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[Addresses_LegalDescriptions_Determinations] CHECK CONSTRAINT [FK_Addresses_LegalDescriptions_Determinations_Determinations]
GO
ALTER TABLE [dbo].[Addresses_LegalDescriptions_Determinations] WITH NOCHECK ADD CONSTRAINT [FK_Addresses_LegalDescriptions_Determinations_LegalDescriptions] FOREIGN KEY([idLegalDescription])
REFERENCES [dbo].[LegalDescriptions] ([idLegalDescription])
ON DELETE CASCADE
NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[Addresses_LegalDescriptions_Determinations] CHECK CONSTRAINT [FK_Addresses_LegalDescriptions_Determinations_LegalDescriptions]
GO
导致错误的表的结构:
CREATE TABLE [dbo].[LegalDescriptions](
[idLegalDescription] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[LotNumber] [varchar](15) NULL,
[BlockNumber] [varchar](15) NULL,
[SubDivision] [varchar](255) NULL,
[UpdatedDate] [datetime] NOT NULL,
[InsertedDate] [datetime] NULL,
[SubDivisionPhase] [varchar](5) NULL,
[Township] [varchar](20) NULL,
[UpdatedidLogin] [smallint] NOT NULL CONSTRAINT [DF_LegalDescriptions_UpdatedidLogin] DEFAULT ((0)),
[InsertedIDLogin] [smallint] NULL,
[LegalDescription] [varchar](255) NULL,
[PinNumber] [varchar](30) NULL,
[Range] [varchar](15) NULL,
[SectionLegalDescription] [varchar](15) NULL,
CONSTRAINT [pkLegalDescriptions] PRIMARY KEY CLUSTERED
(
[idLegalDescription] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [DATA]
) ON [DATA]
GO
SET ANSI_PADDING OFF
GO
我尝试执行存储过程时收到的错误:
Msg 50000,Level 16,State 1,Procedure spRethrowError,Line 42
错误220,级别16,状态1,过程spSaveAddresses_LegalDescriptions_Determinations,第42行
消息:数据类型smallint的算术溢出错误,值= 171922。
我的问题:
此列引发错误[idLegalDescription]的所有数据类型都是INT
,为什么stored procedure
要求smallint
数据类型?我确信它很简单,我不在乎。
答案 0 :(得分:3)
您的专栏
[UpdatedidLogin] [smallint]
填充
@idLegalDescription INT