Saturday, September 19, 2015

PostgreSQL Basic Queries


SCHEMA

- Create Schema 

CREATE SCHEMA schema_name;

- Rename Schema

ALTER SCHEMA schema_name RENAME to schema_name_new

- Drop Schema

DROP SCHEMA schema_name;



DATABASE

- Create DataBase

Create DATABASE database_name;

- Rename DataBase

ALTER DATABASE database_name RENAME to database_name_new;

- Drop DataBase

DROP DATABASE database_name

TABLE

- Create Table

CREATE TABLE table_name(
   col1 text,
   col2 text,
   PRIMARY KEY(col1)
);

- Create table in a schema

CREATE TABLE schema_name.table_name(
   col1 text,
   col2 text,
   PRIMARY KEY(col1)
);

- Rename Table

ALTER table table_name RENAME to table_name_new;

- TRUNCATE table : Delete All Data

TRUNCATE table table_name;

- Drop Table

DROP table table_name;

No comments:

Post a Comment