-1 enttry in first row

Shambhu Rai 1,406 Reputation points

Hi Expert,

How to add -1 entry in first row in auto incremental column like this
CREATE TABLE [dbo].[main6](
[oid][int] identity(1,1) not NULL,
[UNIT1] [int] NULL,
[quantity] [int] NULL,
[SaleDateId] [date] NULL,
[cash] [int] NULL

the column oid is auto incremental . how to add first row as -1 entry in the table for oid

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,879 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,563 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.9K Reputation points

    To start oid from -1, try this statement:

    CREATE TABLE [dbo].[main6] (
       [oid] int identity(-1,1) NOT NULL,
       . . .

    If you want to insert -1 into an existing table, then try this:

    set identity_insert main6 on
    insert into main6 (oid) values (-1)
    set identity_insert main6 off
    select top(10) * from main6 order by oid

    By the way, were the previous answers helpful?

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful