I am trying to create stored procedure that inserts some data into my table, but I'm getting some errors like
Invalid Column name
For all the columns that I specified in my stored procedure. I have an IDENTITY COLUMN called ID which increments by one each time record is inserted. I also have some other columns in the table but they can be null. Here is my stored procedure and cannot figure out what I am doing wrong here.
USE MYDB
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_Test]
@myID bigInt,
@myFirstName nvarchar(50)
,@myLastName nvarchar(50)
,@myAddress nvarchar(MAX)
,@myPort int
AS
BEGIN
SET NOCOUNT ON;
BEGIN
insert into MYDB.dbo.MainTable (MyID, MyFirstName, MyLastName, MyAddress, MyPort)
values(@myID, @myFirstName, @myLastName, @myAddress, @myPort)
END
END
GO
Here is the table definition:
USE [MYDB]
GO
/****** Object: Table [dbo].[MainTable] Script Date: 01/03/2013 11:17:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MainTable](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[MyID] [bigint] NULL,
[MyFirstName] [nvarchar](50) NULL,
[MyLastName] [nvarchar](50) NULL,
[MyAddress] [nvarchar](max) NULL,
[MyPort] [int] NULL,
[MyZipCode] [nchar](10) NULL,
[CompName] [nvarchar](50) NULL
) ON [PRIMARY]
GO
dbo.MainTable
definitely exist in theMyDb
database? – Bridge