Table creation/Postal addresses: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
m (Switched to header template)
Line 3: Line 3:
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.


==[[MySQL]]==
=={{header|MySQL==
[[Category:MySQL]]

CREATE TABLE `Address` (
CREATE TABLE `Address` (
`addrID` int(11) NOT NULL auto_increment,
`addrID` int(11) NOT NULL auto_increment,
Line 15: Line 13:
);
);


==[[MS SQL]]==
=={{header|MS SQL}}==
[[Category:MS SQL]]
[[Category:MS SQL]]
CREATE TABLE #Address (
CREATE TABLE #Address (
Line 26: Line 24:
drop table #Address
drop table #Address


==[[Oracle]]==
=={{header|Oracle}}==
[[Category:Oracle]]
CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
/
/
Line 40: Line 37:
/
/


==[[PostgreSQL]]==
=={{header|PostgreSQL}}==
[[Category:PostgreSQL]]

CREATE SEQUENCE address_seq start 100;
CREATE SEQUENCE address_seq start 100;
CREATE TABLE address (
CREATE TABLE address (
Line 52: Line 47:
);
);


==[[SAS]]==
=={{header|SAS}}==
[[Category:SAS]]

DATA address;
DATA address;
LENGTH addrID 8. street 50$ city 25$ state 2$ zip 20$;
LENGTH addrID 8. street 50$ city 25$ state 2$ zip 20$;
Line 60: Line 53:
RUN;
RUN;


==[[DB2 UDB]]==
=={{header|DB2 UDB}}==
[[Category:DB2 UDB]]

CREATE TABLE Address (
CREATE TABLE Address (
addrID Integer generated by default as identity,
addrID Integer generated by default as identity,

Revision as of 04:02, 13 November 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.

{{header|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;

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
)