Download presentation
Presentation is loading. Please wait.
Published byGeorgia Robinson Modified over 9 years ago
1
COP4710 D ATABASE M ANAGEMENT C ONNECT TO P OSTGRE SQL SEVER VIA PG A DMIN Prof: Dr. Shu-Ching Chen Ta: Hsin-Yu Ha
2
P ROCEDURE OUTLINE Download pgAdmin from http://www.pgadmin.org/http://www.pgadmin.org/ Install pgAdmin Connect to PostgreSQL through pgAdmin Start creating your own database.
3
D OWNLOAD PG A DMIN (1) Click download Go to PgAdmin Website
4
D OWNLOAD PG A DMIN (2) Select the latest reliable version v1.12.3
5
D OWNLOAD PG A DMIN (3)
6
D OWNLOAD PG A DMIN (4) Download pgadmin3-1.12.3.zip and extract.
7
I NSTALL PG A DMIN (1) After extracting the zip file “pgadmin3-1.12.3.zip”, execute the file pgadmin3.msi and start the installation process.
8
I NSTALL PG A DMIN (2)
9
I NSTALL PG A DMIN (3)
10
I NSTALL PG A DMIN (4) The installation is successfully finished
11
C ONNECT TO P OSTGRE SQL (1) Open pgAdmin and add a connection to a server
12
C ONNECT TO P OSTGRE SQL (2) Name for server connection Hosted server: cop4710- postgresql.cs.fiu.edu Database Name: spr13_”fiu_account” Username: spr13 _”fiu_account” Password: Panther ID
13
C REATE A DATABASE (1) Create table CREATE TABLE products ( product_no integer PRIMARY KEY, name text NOT NULL, price numeric ); Constraints: (1)NOT NULL (2)UNIQUE (3)CHECK Boolean expression For instance CHECK (price>0) (4) PRIMARY KEY (5) FOREIGN KEY CREATE TABLE order_items ( product_no integer REFERENCES products, order_id integer REFERENCES orders, quantity integer, PRIMARY KEY (product_no, order_id), CONSTRAINT cq CHECK (quantity > 5) ); Primary key and Foreign key
14
C REATE A DATABASE (2) Foreign Key CREATE TABLE t1 ( a integer PRIMARY KEY, b integer, c integer, FOREIGN KEY (b, c) REFERENCES other_table (c1, c2) ); CREATE TABLE other_table ( c1 integer PRIMARY KEY, c2 integer );
15
C REATE A DATABASE (3) CREATE TABLE products ( product_no integer PRIMARY KEY, name text, price numeric ); CREATE TABLE orders( order_id integer PRIMARY KEY, shipping_address text, … ); CREATE TABLE order_items ( product_no integer REFERENCES products ON DELETE RESTRICT, order_id integer REFERENCES orders ON DELETE CASCADE, quantity integer, PRIMARY KEY (product_no, order_id) );
16
C REATE A DATABASE (4) Insert Data INSERT INTO products (product_no, name,price) VALUES (1,'cheese',5); INSERT INTO products VALUES (1,'cheese',5), (2,’cake’,10) ;
17
C REATE A DATABASE (5) Import Data Export Data COPY country TO '/sql/country_data.csv' WITH DELIMITER '|'; COPY country FROM '/usr1/proj/bray/sql/country_data.csv' WITH DELIMITER ',' ;
18
C REATE A DATABASE (6) ALTER Table Add columns Remove columns Add constraints ALTER TABLE products ADD COLUMN description text; ALTER TABLE products DROP COLUMN description; ALTER TABLE products ADD CONSTRAINT namecheck CHECK (name <> ''); ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no); ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups; ALTER TABLE products ALTER COLUMN product_no SET NOT NULL;
19
C REATE A DATABASE (7) ALTER Table Remove constraints Change column data types Rename columns Rename tables ALTER TABLE products DROP CONSTRAINT some_name ; ALTER TABLE products ALTER COLUMN product_no DROP NOT NULL; ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2); ALTER TABLE products RENAME COLUMN product_no TO product_number; ALTER TABLE products RENAME TO items;
20
C REATE A DATABASE (8) Delete Data DELETE FROM products WHERE price = 10; DELETE FROM products
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.