Category: Postgresql
-
PostgreSQL Select Data
Select Data To retrieve data from a data base, we use the SELECT statement. Specify Columns By specifying the column names, we can choose which columns to select: Example Run Example » Return ALL Columns Specify a * instead of the column names to select all columns: Example Run Example » PostgreSQL Exercises Test Yourself With Exercises Exercise: Write the correct…
-
PostgreSQL Operators
Operators in the WHERE clause We can operate with different operators in the WHERE clause: = Equal to < Less than > Greater than <= Less than or equal to >= Greater than or equal to <> Not equal to != Not equal to LIKE Check if a value matches a pattern (case sensitive) ILIKE Check if…
-
PostgreSQL DROP TABLE
The DROP TABLE Statement The DROP TABLE statement is used to drop an existing table in a database. Note: Be careful before dropping a table. Deleting a table will result in loss of all information stored in the table! The following SQL statement drops the existing table cars: Example Delete the cars table: Result Display Table To check the result we…
-
PostgreSQL DELETE
The DELETE Statement The DELETE statement is used to delete existing records in a table. Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause,all records in the table will be deleted!. To delete the record(s) where brand is ‘Volvo’, use this statement: Example…
-
PostgreSQL DROP COLUMN
The ALTER TABLE Statement To remove a column from a table, we have to use the ALTER TABLE statement. The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table. DROP COLUMN We want to remove the column named color from…
-
PostgreSQL ALTER COLUMN
The ALTER TABLE Statement To change the data type, or the size of a table column we have to use the ALTER TABLE statement. The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table. ALTER COLUMN We want…
-
PostgreSQL UPDATE
The UPDATE Statement The UPDATE statement is used to modify the value(s) in existing records in a table. Example Set the color of the Volvo to ‘red’: Result UPDATE 1 Which means that 1 row was affected by the UPDATE statement. Note: Be careful with the WHERE clause, in the example above ALL rows where brand = ‘Volvo’ gets updated. Display Table To check…
-
PostgreSQL ADD COLUMN
The ALTER TABLE Statement To add a column to an existing table, we have to use the ALTER TABLE statement. The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table. ADD COLUMN We want to add a column…
-
PostgreSQL Select Data
Select Data To retrieve data from a data base, we use the SELECT statement. Specify Columns By specifying the column names, we can choose which columns to select: Example Return ALL Columns Specify a * instead of the column names to select all columns: Example PostgreSQL Exercises Test Yourself With Exercises Exercise: Write the correct SQL statement to select all columns,…
-
PostgreSQL Insert Data
Insert Into To insert data into a table in PostgreSQL, we use the INSERT INTO statement. The following SQL statement will insert one row of data into the cars table you created in the previous chapter. INSERT INTO cars (brand, model, year)VALUES (‘Ford’, ‘Mustang’, 1964); The SQL Shell application will return the following: INSERT 0 1 Which means that 1 row was…