Kwok Peng Tuck wrote:
>
> Can anyone provide a sql schema for creating a table which utilizes a
> sequence to generate its primary key.
> I'm having problems doing so in SQL studio.
> Specifically most of my sql code is giving me errors here's a sample :
>
>
> CREATE TABLE films (
> code CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY,
> title CHARACTER VARYING(40) NOT NULL,
> did DECIMAL(3) NOT NULL,
> date_prod DATE,
> kind CHAR(10),
> len INTERVAL HOUR TO MINUTE
> );
>
> CREATE TABLE distributors (
> did DECIMAL(3) PRIMARY KEY DEFAULT NEXTVAL('serial'),
> name VARCHAR(40) NOT NULL CHECK (name <> '')
> );
For a general description of the create table syntax and the supported data types
see: http://www.sapdb.org/htmhelp/6d/117c14d14811d2a97400a0c9449261/frameset.htm
For the special case of a table with an automatic generated primary key
use a DEFAULT SERIAL spec, i.e.
CREATE TABLE distributors (
did FIXED(10) DEFAULT SERIAL,
name VARCHAR(40) NOT NULL CHECK (name <> ''),
PRIMARY KEY (did) )
You may find a lot of postings about SERIAL and SEQUENCE on the mailing list archives
see: http://www.sapdb.org/sap_db_contact.htm
HTH.
Kind regards,
Holger
SAP Labs Berlin
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general