Sunday, February 12, 2012

Auto Incrent Attribute SQL Server 2000 vs Sql Server 2005

In our application we use the ADODB.Recordset.

In SQL server 2000

If there was a view that joined 2 tables and I accessed the view the 2 ID fields in the view would still have the AutoIncrement attribute still set to true so that I knew those were Identity fields.

In SQL server 2005

I dont' know why but if you reference a View that has Identiy AutoInc fields in ADO it doesn't keep those properties.

Also for whatever reason we Set the ID field to 0 to let ourselves know its a new Record. SQL 2000 let it happen and assumed it to be null where as By Setting the ID to 0 in SQL 2005 causes it to blow up on me.

Is there some sort of setting in SQL that can make SQL 2005 work like SQL 2000 in these two instances...

CREATE TABLE [dbo].[table1](
[field1] [int] IDENTITY(1,1) NOT NULL,
[field2] [varchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[field3] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_table1] PRIMARY KEY CLUSTERED
(
[field1] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

above example sql script create table with auto incrent. field (field1)

note: IDENTITY(1,1) keyword.

argument of IDENTITY indicate start and inc. value respiectivey.

No comments:

Post a Comment