Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sybase Insert

Status
Not open for further replies.

SpeedKing

Technical User
Joined
Mar 18, 2002
Messages
2
Location
SE
I am trying to insert into a sybase table. One of the fields called log_id is defined as an int and it is my primary key. This table is used for logging user transactions and I need this log_id column to be increased by one each time an insert is performed. What is the synatx.

I know in Informix when inserting on a serial column, with a value of zero, this will give you the next value for a primary key.

Help

SK
 
If the field is int, you'll have to do it manually, i.e. get the max(log_id), add 1, and use that as the key value.

A better way would be to define log_id as an identity column - that's the Sybase equivalent of serial. You don't even need to supply a value during insert, Sybase takes care of it. The identity column must be of type numeric with a scale of 0, and not null must be specified, e.g.
[tt]
create table mytab
(log_id numeric(10,0) identity not null,
column2 char(20))
[/tt]

I would suggest you re-define the table as above, as I makes things a lot easier in the long run.

Greg. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top