October 26, 2003 at 2:36 am
I have the following table,
CREATE TABLE [dbo].[tbl_Users] (
[UserId] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Password] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[HeadLine] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Title] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[FirstName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[LastName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Email] [nvarchar] (75) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SecretWordType] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SecretWord] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Age] [int] NOT NULL ,
[DOB] [datetime] NOT NULL ,
[Gender] [nvarchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[City] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[StateProvince] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Country] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DateCreated] [datetime] NOT NULL
) ON [PRIMARY]
GO
I created the proc
CREATE PROCEDURE [dbo].[insert_registration] (
@UserName nvarchar (50) ,
@Password nvarchar(50) ,
@HeadLine nvarchar(50),
@Title nvarchar (10) ,
@FirstName nvarchar (50) ,
@LastName nvarchar (50) ,
@Email nvarchar (75) ,
@SecretWordType nvarchar (50) ,
@SecretWord nvarchar (50) ,
@Age int ,
@DOB datetime ,
@Gender nvarchar (6) ,
@City nvarchar (50) ,
@StateProvince nvarchar (50) ,
@Country nvarchar (50) ,
@DateCreated datetime) AS
INSERT INTO dbo.tbl_Users VALUES(@Username, @Password,@HeadLine, @Title,
@FirstName, @LastName,@Email, @SecretWordType, @SecretWord, @Age,
@DOB,@Gender,@City, @StateProvince,@Country,@DateCreated )
GO
I am not sure how to increment or implement the userid in stored procs. And should I be using Inserting Data Using Parameters.
It has been 3 years.
October 26, 2003 at 3:55 am
Everything in your code looks fine - did it fail for you?
When inserting with an identity column, just leave that column out of the insert.
Ex:
create table tbl_users
(
idcol int IDENTITY (1, 1) NOT NULL ,
col2 varchar(12) NULL
)
insert into tbl_users values ('Jeff')
insert into tbl_users values ('Madsen')
select * from tbl_users
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply