CREATE table food( name TEXT NOT NULL, calories INT, carbs INT, protein REAL, fat REAL, place TEXT NOT NULL); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('mcplant',429,40,19,20,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('vegetable deluxe',361,51,8.8,12,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('spicy veggie one',365,59,8.7,8.8,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('veggie dippers 4pc',321,41,6.6,13,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('mc fries med',337,42,3.3,17,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('side salad',18,2.1,0.9,0.5,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('cookie crumble mcflurry',356,51,6.2,14,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('mc med fanta',76,18,0,0,'mcdonalds'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('plant based whopper',555,55.1,24.3,27,'burger king'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('vegan royale',571,52.4,17.1,30.8,'burger king'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('bk fries large',382,46.3,4.9,17.8,'burger king'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('vegan nuggets 6pc',243,21.5,7.9,12.9,'burger king'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('onion rings 9pc',337,42,6.9,14.7,'burger king'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('bk med fanta',86,20.5,0,0,'burger king'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('plant patty',371,50,18,10,'subway'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('veggie delite',217,43,7.6,1.3,'subway'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('vegan burger',450,45.2,16.4,18,'kfc'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('kfc fries large ',345,49.1,4.7,16.6,'kfc'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('vegan burger',450,45.2,16.4,18,'kfc'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('veggie salad',235,25.5,6,6.6,'kfc'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('club orange reg',160,39,0,0,'kfc'); INSERT INTO food(name,calories,carbs,protein,fat,place) VALUES ('chocolate sundae',210,31.3,3.5,7.7,'kfc'); SELECT * FROM food;
Write, Run & Share PostgreSQL queries online using OneCompiler's PostgreSQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for PostgreSQL. Getting started with the OneCompiler's PostgreSQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose database as 'PostgreSQL' and start writing queries to learn and test online without worrying about tedious process of installation.
PostgreSQL is a open source relational database system and is also knows as Postgres.
CREATE command is used to create a table, schema or an index.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
....);
ALTER command is used to add, modify or delete columns or constraints from the database table.
ALTER TABLE Table_name ADD column_name datatype;
TRUNCATE command is used to delete the data present in the table but this will not delete the table.
TRUNCATE table table_name;
DROP command is used to delete the table along with its data.
DROP TABLE table_name;
RENAME command is used to rename the table name.
ALTER TABLE table_name1 RENAME to new_table_name1;
INSERT Statement is used to insert new records into the database table.
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Select statement is used to select data from database tables.
SELECT column1, column2, ...
FROM table_name;
UPDATE statement is used to modify the existing values of records present in the database table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE statement is used to delete the existing records present in the database table.
DELETE FROM table_name where condition;