If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > how to reseed the identity column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-11, 06:33
lahari lahari is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
how to reseed the identity column

Hi ,

As per requirement i need to start the identity column with 1000 and increment by 1.

i have tried the following code but its not working.
CREATE TABLE ORDERS(
OrderID int identity [(100,10)] NOT FOR REPLICATION,
CustID int,
OrderDate datetime
)

Can some one shed light on the proper syntax for the above problem.

Thanks,
Lahari.
Reply With Quote
  #2 (permalink)  
Old 07-13-11, 11:43
pradyut.dhara pradyut.dhara is offline
Registered User
 
Join Date: May 2011
Posts: 28
Hi,
Correct syntax would be
CREATE TABLE ORDERS(
OrderID numeric(38,0) identity ,
CustID int,
OrderDate datetime
)
go
Please refer to the link below for more details:
Transact-SQL User's Guide
Reply With Quote
  #3 (permalink)  
Old 07-13-11, 12:08
pradyut.dhara pradyut.dhara is offline
Registered User
 
Join Date: May 2011
Posts: 28
Hi,
I think you have to insert manually first setting identity_insert option on for the table ORDERS as explained in the link below:
SyBooks Online

1> set identity_insert ORDERS on
2> go
1> insert into ORDERS(OrderID,CustID,OrderDate) values (1000,1,getdate())
2> go
(1 row affected)
1> select * from ORDERS
2> go
OrderID CustID OrderDate
----------------------------------------- ----------- --------------------------
1000 1 Jul 13 2011 9:37PM

(1 row affected)
1> insert into ORDERS(CustID,OrderDate) values (1,getdate())
2> go
Msg 585, Level 16, State 1:
Server 'PKD', Line 1:
Explicit value must be specified for identity field in table 'ORDERS' when IDENTITY_INSERT or IDENTITY_UPDATE is ON.
1> set identity_insert ORDERS off
2> go
1> insert into ORDERS(CustID,OrderDate) values (2,getdate())
2> go
(1 row affected)
1> select * from ORDERS
2> go
OrderID CustID OrderDate
----------------------------------------- ----------- --------------------------
1000 1 Jul 13 2011 9:37PM
1001 2 Jul 13 2011 9:37PM

(2 rows affected)
1>
Reply With Quote
Reply

Tags
identity

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On