-- create tabla lectores CREATE TABLE Lectores ( lectorID INTEGER PRIMARY KEY, nombre TEXT NOT NULL, apellido TEXT NOT NULL, email TEXT NOT NULL, nacimiento TEXT ); -- create tabla Libros CREATE TABLE Libros ( libroID INTEGER PRIMARY KEY, nombreLibro TEXT NOT NULL, nombreEditorial TEXT NOT NULL, autor TEXT NOT NULL, ISBN INTEGER NOT NULL ); -- insert lectores INSERT INTO Lectores VALUES (0001, 'Juan Alberto', 'Cortez', '[email protected]', '20/06/1983'); INSERT INTO Lectores VALUES (0002, 'Antonia', 'de los Ríos', '[email protected]', '24/11/1978'); INSERT INTO Lectores VALUES (0003, 'Nicolas', 'Martin', '[email protected]', '11/07/1986'); INSERT INTO Lectores VALUES (0004, 'Nestor', 'Casco', '[email protected]', '11/02/1981'); INSERT INTO Lectores VALUES (0005, 'Lisa', 'Pérez', '[email protected]', '11/08/1994'); INSERT INTO Lectores VALUES (0006, 'Ana Rosa', 'Estagnolli', '[email protected]', '15/10/1974'); INSERT INTO Lectores VALUES (0007, 'Milagros', 'Pastoruti', '[email protected]', '22/01/2001'); INSERT INTO Lectores VALUES (0008, 'Pedro', 'Alonso', '[email protected]', '05/09/1983'); INSERT INTO Lectores VALUES (0009, 'Arturo Ezequiel', 'Ramírez', '[email protected]', '29/03/1998'); INSERT INTO Lectores VALUES (0010, 'Juan Ignacio', 'Altarez', '[email protected]', '24/08/1975'); -- insert libros INSERT INTO Libros VALUES (0001, 'Cementerio de animales', 'Ediciones de Mente', 'Stephen King', 4568874); INSERT INTO Libros VALUES (0002, 'En el nombre de la rosa', 'Editorial España', 'Umberto Uco', 44558877); INSERT INTO Libros VALUES (0003, 'Cien años de soledad', 'Sudamericana', 'Gabriel Garcia Márquez', 7788845); INSERT INTO Libros VALUES (0004, 'El diario de Ellen Rimbauer', 'Editorial Maine', 'Stephen King', 45699874); INSERT INTO Libros VALUES (0005, 'La hojarasca', 'Sudamericana', 'Gabriel Garcia Marquez', 7787898); INSERT INTO Libros VALUES (0006, 'El amor en los tiempos de cólera', 'Sudamericana', 'Gabriel Garcia Marquez', 2564111); INSERT INTO Libros VALUES (0007, 'La casa de los espíritus', 'Ediciones Chile', 'Isabel Allende', 5544781); INSERT INTO Libros VALUES (0008, 'Paula', 'Ediciones Chile', 'Isabel Allende', 22545447); INSERT INTO Libros VALUES (0009, 'La tregua', 'Alfa', 'Mario Benedetti', 2225412); INSERT INTO Libros VALUES (0010, 'Gracias por el fuego', 'Alfa', 'Mario Benedetti', 88541254); -- fetch SELECT * FROM Lectores WHERE apellido = 'Casco'; SELECT * FROM Libros WHERE nombreEditorial= 'Alfa';
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;