Creating PostgreSQL Databases
Darryl Reeves
Industry Assistant Professor, New York University
CREATE TABLE textbook (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
publisher_name VARCHAR(100) NOT NULL,
publisher_site VARCHAR(50),
quantity SMALLINT NOT NULL DEFAULT 0
);
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.abc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
112 | Statistical Concepts | Martin House | www.mh.com | 22 |
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.abc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
112 | Statistical Concepts | Martin House | www.mh.com | 22 |
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.newabc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
112 | Statistical Concepts | Martin House | www.mh.com | 22 |
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.abc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
112 | Statistical Concepts | Martin House | www.mh.com | 22 |
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.abc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
112 | Statistical Concepts | Martin House | www.mh.com | 22 |
?? | ?? | New Horizons | www.nhorizon.com | ?? |
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.abc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
112 | Statistical Concepts | Martin House | www.mh.com | 22 |
id | title | publisher_name | publisher_site | quantity |
---|---|---|---|---|
23 | Introductory Algebra: 1st Edition | ABC Publishing | www.abc.com | 32 |
74 | Calculus Foundations | ABC Publishing | www.abc.com | 27 |
PRIMARY KEY
CREATE TABLE textbook (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
publisher_name VARCHAR(100) NOT NULL,
publisher_site VARCHAR(50),
quantity SMALLINT NOT NULL DEFAULT 0
);
CREATE TABLE textbook (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
quantity SMALLINT NOT NULL DEFAULT 0,
);
CREATE TABLE publisher (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
site VARCHAR(50)
);
CREATE TABLE textbook (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
quantity SMALLINT NOT NULL DEFAULT 0,
publisher_id INTEGER REFERENCES publisher(id)
);
CREATE TABLE publisher (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
site VARCHAR(50)
);
Creating PostgreSQL Databases