Table creation/Postal addresses: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎[[UDB DB2]]: Actually, it's DB2 UDB.)
(→‎[[Oracle SQL]]: There's ambiguity as to whether to call it Oracle or Oracle SQL. I renamed everything to Oracle.)
Line 15: Line 15:
);
);


==[[Oracle SQL]]==
==[[Oracle]]==
[[Category:Oracle SQL]]
[[Category:Oracle]]
CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
/
/

Revision as of 17:06, 26 January 2007

Task
Table creation/Postal addresses
You are encouraged to solve this task according to the task description, using any language you may know.

In this task, the goal is to create a table to store addresses.

MySQL

CREATE TABLE `Address` (
  `addrID`       int(11)     NOT NULL   auto_increment,
  `addrStreet`   varchar(50) NOT NULL   default ,
  `addrCity`     varchar(25) NOT NULL   default ,
  `addrState`    char(2)     NOT NULL   default ,
  `addrZIP`      char(10)    NOT NULL   default ,
  PRIMARY KEY (`addrID`)
);

Oracle

CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
/
CREATE TABLE address (
  addrID   NUMBER DEFAULT seq_address_pk.nextval,
  street   VARCHAR2( 50 ) NOT NULL,
  city     VARCHAR2( 25 ) NOT NULL,
  state    VARCHAR2( 2 ) NOT NULL,
  zip      VARCHAR2( 20 ) NOT NULL,
  CONSTRAINT address_pk1 PRIMARY KEY ( addrID )
)
/

PostgreSQL

CREATE SEQUENCE address_seq start 100;
CREATE TABLE address (
  addrID   int4 PRIMARY KEY DEFAULT nextval('address_seq'),
  street   varchar(50) not null,
  city     varchar(25) not null,
  state    varchar(2) not null,
  zip      varchar(20) not null
);

SAS

DATA address;
  LENGTH addrID 8. street 50$ city 25$ state 2$ zip 20$;
  STOP;
RUN;

DB2 UDB

CREATE TABLE Address (
	addrID		Integer		generated by default as identity,
	addrStreet	Varchar(50)	not null,
	addrCity	Varchar(25)	not null,
	addrState	Char(2)		not null,
	addrZIP		Char(10)	not null
)