PostgreSQL Syntax Examples

1. Basic SQL Commands

Connect to a database:

\c dbname user

Create a table:

CREATE TABLE tablename ( column1 datatype, column2 datatype, ... );

Insert data into a table:

INSERT INTO tablename (column1, column2, ...) VALUES (value1, value2, ...);

Retrieve data from a table:

SELECT column1, column2, ... FROM tablename WHERE condition;

2. Advanced SQL Commands

Create an index:

CREATE INDEX indexname ON tablename (column1, column2, ...);

Perform a JOIN operation:

SELECT column1, column2, ... FROM table1 INNER JOIN table2 ON table1.column = table2.column;

Update data in a table:

UPDATE tablename SET column1 = value1, column2 = value2, ... WHERE condition;

Delete data from a table:

DELETE FROM tablename WHERE condition;

3. Official Documentation Links

Explore the official PostgreSQL documentation for a comprehensive guide on SQL commands, data types, indexes, and more.

0 Comment:

Post a Comment