PostgreSql Tutorial 3 -- Create , Select , Delete Database

Опубликовано: 19 Февраль 2020
на канале: txt2text
1,613
30

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


Смотрите видео PostgreSql Tutorial 3 -- Create , Select , Delete Database онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь txt2text 19 Февраль 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,61 раз и оно понравилось 3 людям.