Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP5725 DATABASE MANAGEMENT POSTGRESQL TUTORIAL

Similar presentations


Presentation on theme: "COP5725 DATABASE MANAGEMENT POSTGRESQL TUTORIAL"— Presentation transcript:

1 COP5725 DATABASE MANAGEMENT POSTGRESQL TUTORIAL
Prof: Dr. Shu-Ching Chen TA: Sheng Guan

2 Procedure outline Connect to server Connect to database
Add tables through the gui Add tables through sql query tool Check your result after changing Run other sql queries in sql query tool PostgreSQL, often simply Postgres, is an object-relational database management system (ORDBMS) available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows and Mac OS X MySQL vs PostgreSQL is a decision many must make when approaching open-source relational database management systems. Both are time-proven solutions that compete strongly with proprietary database software. MySQL has long been assumed to be the faster but less full-featured of the two database systems, while PostgreSQL was assumed to be a more densely featured database system often described as an open-source version of Oracle. MySQL has been popular among various software projects because of its speed and ease of use, while PostgreSQL has had a close following from developers who come from an Oracle or SQL Server background. These assumptions, however, are mostly outdated and incorrect. MySQL has come a long way in adding advanced functionality while PostgreSQL dramatically improved its speed within the last few major releases. Many, however, are unaware of the convergence and still hold on to stereotypes based on MySQL 4.1 and PostgreSQL 7.4. The current versions are MySQL 5.7 and PostgreSQL 9.4. For new projects, determine if you are going to port to closed software later on. In that case, PostgreSQL is closer to Oracle, and any code made for PostgreSQL will port to Oracle easily. MySQL has moved away from the SQL standard somewhat. PostgreSQL is more reliable because it is ACID (Atomicity, Consistency, Isolation, and Durability) compliant which means queries will maintain data integrity, and return the same output without error. MySQL is less reliable and not ACID compliant: The way it handles foreign key references, auditing and transactions make it less reliable. MySQL is good if you are thinking you may use code from other open source projects. Since it is widely used in smaller websites, there are plenty of add-ons, plugins and modules to optimize MySQL from popular software like Wordpress, Drupal and Joomla.

3 Connect to server Right click “COP5725” at the left “Object browser” panel to connect host server, and select “Connect”, and enter your password Right click and select “Connect” Input your panther ID

4 Connect to server If you are connecting from off-campus, you are required to input SSH tunnel password Input First Initial+ PantherID +Last Initial

5 Some tips Here if you encounter error, please check your PgAdmin version whether is updated – PgAdmin III 1.22 If you believe the order of your default first initial and last initial is wrong, please kindly try different combinations Sometimes, PgAdmin will go back to normal after you close the program and restart

6 Connect to database The server should now be shown in the left hand box and you can navigate your way round your database tables.

7 Add tables through the gui
YourDB->Schemas->public->Tables, Right click to bring up create “New Table” dialogue

8 Add tables through the gui
Here, we use a “cities” table as an example

9 Add tables through the gui
Add attributes to the table: Click “Columns” tab, click “Add” button, and enter “name” in the Name text box, “Data type” as character and “Length” as 60

10 Add tables through the gui
You can add more attributes to the table, such as “location” , “country”, and so on using the same way Your “cities” table will look like:

11 Add tables through the gui
Finally, add one constraint for “cities” table. This would be the primary key. Click “Constraints” tab -> “Add” button. A new dialogue for adding a new primary key will show up. Enter the “pk_city_name” as the key name, Click “Columns”, and connect the key to a city name field of the table we created by selecting “name”. Then we will see that our primary key is created and added in the panel.

12 Add tables through the gui
1 2 4 3

13 Add tables through the gui
Now we have specified the Table name, Attribute (column) names, Data types, Constraint (primary key , to prevent from duplicated records with the same city being added to the table).

14 Add tables through sql query tool
SQL Icon Run SQL Query Run and Save SQL Query Write SQL query here

15 SQL command to create table
You can select your query and press “F5” in space line to save and run the above query

16 Check your result after changing
Similarly, we create a new “weather” table in the DB Now we want to check the changes: Now back to Object browser and right click “Your Database”, select Refresh, expand your database, you will notice our new “weather” table with columns and constraint (primary key) created.

17 Try other sql query in query tool
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; DELETE FROM products WHERE price = 10;


Download ppt "COP5725 DATABASE MANAGEMENT POSTGRESQL TUTORIAL"

Similar presentations


Ads by Google