PostgreSql Tutorial 3 -- Create , Select , Delete Database
---------------------------------------------------------------------------------------------------------------------------------------------------------
Create the Database:
This command will create a database from PostgreSQL shell prompt, but you should have appropriate privilege to create a database. By default, the new database will be created by cloning the standard system database template1.
Syntax:
The basic syntax of CREATE DATABASE statement is as follows −
CREATE DATABASE dbname;
where dbname is the name of a database to create.
Example:
The following is a simple example, which will create testdb in your PostgreSQL schema
postgres=# CREATE DATABASE testdb;
postgres-#
=============================================================================
Select the database Statement
1.) Database SQL Prompt
2.) OS Command Prompt
1.) Database SQL Prompt
Assume you have already launched your PostgreSQL client and you have landed at the following SQL prompt −
postgres=#
You can check the available database list using \l, i.e., backslash el command as follows −
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------+----------+----------+---------+-------+----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | C | C |
(4 rows)
postgres-#
Now, type the following command to connect/select a desired database; here, we will connect to the testdb database.
postgres=# \c testdb;
psql (9.2.4)
Type "help" for help.
You are now connected to database "testdb" as user "postgres".
testdb=#
2.)OS Command Prompt
You can select your database from the command prompt itself at the time when you login to your database. Following is a simple example −
psql -h localhost -p 5432 -U postgress testdb
Password for user postgress: ****
psql (9.2.4)
Type "help" for help.
You are now connected to database "testdb" as user "postgres".
testdb=#
=============================================================================
Delete the database
There are two options to delete a database −
1.) Using DROP DATABASE, an SQL command.
2.) Using dropdb a command-line executable.
Be careful before using this operation because deleting an existing database would result in loss of complete information stored in the database.
#postgreSql #govindsharma
Auf dieser Seite können Sie das Online-Video PostgreSql Tutorial 3 -- Create , Select , Delete Database mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer txt2text 19 Februar 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,613 Mal angesehen und es wurde von 30 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!