SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
CREATE TABLE Storage ( Storage_key SERIAL PRIMARY KEY, Quantity INTEGER CHECK (Quantity > 0) NOT NULL, Delivery_Date DATE CHECK (Delivery_Date <= CURRENT_DATE) NOT NULL, Price DECIMAL(10, 2) NOT NULL, Consumed_date DATE CHECK (Consumed_date >= CURRENT_DATE) NOT NULL ); CREATE TABLE Sold_Medicines ( Sold_key SERIAL PRIMARY KEY, Quantity int CHECK (Quantity > 0) NOT NULL, Sale_Date DATE CHECK (Sale_Date <= CURRENT_DATE) NOT NULL, Storage_key INT NOT NULL, FOREIGN KEY (Storage_key) REFERENCES Storage(Storage_key) ON UPDATE CASCADE ON DELETE RESTRICT ); INSERT INTO Storage (Quantity, Delivery_Date, Price, Consumed_date) VALUES (100, '2023-04-10', 20.00, '2023-05-10'); INSERT INTO Storage (Quantity, Delivery_Date, Price, Consumed_date) VALUES (50, '2023-04-12', 15.00, '2023-05-15'); INSERT INTO Storage (Quantity, Delivery_Date, Price, Consumed_date) VALUES (75, '2023-02-15', 25.00, '2023-05-20'); INSERT INTO Storage (Quantity, Delivery_Date, Price, Consumed_date) VALUES (200, '2023-02-16', 30.00, '2023-05-16'); INSERT INTO Storage (Quantity, Delivery_Date, Price, Consumed_date) VALUES (125, '2023-02-17', 18.00, '2023-05-18'); INSERT INTO Sold_Medicines (Quantity, Sale_Date, Storage_key) VALUES (20, '2023-04-13', 1); INSERT INTO Sold_Medicines (Quantity, Sale_Date, Storage_key) VALUES (30, '2023-04-14', 1); INSERT INTO Sold_Medicines (Quantity, Sale_Date, Storage_key) VALUES (40, '2023-04-15', 2); INSERT INTO Sold_Medicines (Quantity, Sale_Date, Storage_key) VALUES (10, '2023-04-15', 2); DROP FUNCTION sell_medicine(integer,integer); CREATE OR REPLACE FUNCTION sell_medicine( storage_key INTEGER, quantity INTEGER ) RETURNS VOID AS $$ DECLARE storage_quantity INTEGER; BEGIN SELECT Quantity INTO STRICT storage_quantity FROM Storage WHERE Storage_key = sell_medicine.storage_key; IF storage_quantity < quantity THEN RAISE EXCEPTION 'Недостаточно товара на складе'; END IF; UPDATE Storage SET Quantity = Quantity - quantity WHERE Storage_key = sell_medicine.storage_key; INSERT INTO Sold_Medicines (Quantity, Sale_Date, Storage_key) VALUES (quantity, CURRENT_DATE, sell_medicine.storage_key); END; $$ LANGUAGE plpgsql; SELECT sell_medicine(1, 10);
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear