Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 21455
  • Last Modified:

Sybase 11 - Create a table with AUTOINCREMENT field

Hi,

I want to create a table with an autoincrement field, with the following syntax:

CREATE TABLE auto1
( primary1 INTEGER NOT NULL DEFAULT AUTOINCREMENT,
data1 INTEGER NOT NULL,
PRIMARY KEY ( primary1 ) );

Sybase reports with an error:

Incorrect syntax near the keyword 'DEFAULT'.

I've tried every possible combination, such as removing NOT NULL, DEFAULT, etc.. However, the only way to create the table successfully is to remove the AUTOINCREMENT syntax.

Or is there any option in Sybase to turn off the autoincrement feature?

Anyone can help? Thank you.
0
keewooi
Asked:
keewooi
  • 2
  • 2
1 Solution
 
ahoorCommented:
I suppose you use Sybase ASE? autoincrement is not Sybase-syntax, use"identity" instead.

CREATE TABLE auto1
( primary1 numeric(10) identity,
data1 INTEGER NOT NULL,
PRIMARY KEY ( primary1 ) )

Also use the numeric datatype for identity columns, you get to decide how big it should be yourself. Since you wanted to use integer I think numeric(10) will do.

0
 
keewooiAuthor Commented:
Thank you so much, it has solved my problem!

Now, can you please tell me, whether or not it's fine to use numeric(10) to replace INT?
0
 
ahoorCommented:
Sure it's fine... numeric(10) means you can have numbers up to 9.999.999.999. That's almost 7.000.000.000 more than an integer highest value.
0
 
keewooiAuthor Commented:
Okay. Thans for the sulution. I appreciate that.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now