Reputation: 3213
Good Evening All,
I've created the following stored procedure:
CREATE PROCEDURE AddQuote
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @CompanyName nvarchar(50),
@Addr nvarchar(50),
@City nvarchar(50),
@State nvarchar(2),
@Zip nvarchar(5),
@NeedDate datetime,
@PartNumber float,
@Qty int
-- Insert statements for procedure here
Insert into dbo.Customers
(CompanyName, Address, City, State, ZipCode)
Values (@CompanyName, @Addr, @City, @State, @Zip)
Insert into dbo.Orders
(NeedbyDate)
Values(@NeedDate)
Insert into dbo.OrderDetail
(fkPartNumber,Qty)
Values (@PartNumber,@Qty)
END
GO
When I execute AddQuote, I receive an error stating:
Msg 515, Level 16, State 2, Procedure AddQuote, Line 31
Cannot insert the value NULL into column 'ID', table 'Diel_inventory.dbo.OrderDetail'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I understand that I've set Qty field to not allow nulls and want to continue doing so. However, are there other syntax changes I should make to ensure that this sproc works correctly?
Thanks, Sid
Upvotes: 0
Views: 1440
Reputation: 432742
so
Upvotes: 1
Reputation: 48516
Looks to me like you forgot to enable "identity specification" for the ID column of the OrderDetail table. It has nothing to do with your stored procedure per se.
You will need to recreate the table to make the ID column have IDENTITY
, but SQL Management Studio will script that for you.
Upvotes: 1