Table creation/Postal addresses: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|MySQL: Oops. Missed.)
m (Alphabetized)
Line 2: Line 2:


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

=={{header|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
)


=={{header|MySQL}}==
=={{header|MySQL}}==
Line 52: Line 61:
STOP;
STOP;
RUN;
RUN;

=={{header|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
)

Revision as of 21:07, 15 December 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.

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
)

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`)
);

MS SQL

CREATE TABLE #Address (
  addrID       int        NOT NULL   Identity(1,1) PRIMARY KEY,
  addrStreet   varchar(50) NOT NULL ,  
  addrCity     varchar(25) NOT NULL , 
  addrState    char(2)     NOT NULL , 
  addrZIP      char(10)    NOT NULL  
)
drop table #Address

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;