Hi! Could we please enable some services and cookies to improve your experience and our website?
No, thanks.
Okay!
SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share code
Donate
Blog
Popular
FAQ
Donate
A
A
A
Share
Blog
Popular
FAQ
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
SQL code:
Upload
Copy
Format
Clear
import sqlite3 # Connect to the SQLite database (or create it) conn = sqlite3.connect('hospital.db') cursor = conn.cursor() # Create the Patient table if it doesn't exist cursor.execute(''' CREATE TABLE IF NOT EXISTS Patient ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, issue TEXT, age INTEGER ) ''') # Functions to insert, delete, update patients def insert_patient(name, issue, age): cursor.execute('INSERT INTO Patient (name, issue, age) VALUES (?, ?, ?)', (name, issue, age)) conn.commit() def delete_patient(patient_id): cursor.execute('DELETE FROM Patient WHERE id = ?', (patient_id,)) conn.commit() def update_patient(patient_id, name=None, issue=None, age=None): row = cursor.execute('SELECT * FROM Patient WHERE id=?', (patient_id,)).fetchone() if not row: print("Patient not found.") return new_name = name if name is not None else row[1] new_issue = issue if issue is not None else row[2] new_age = age if age is not None else row[3] cursor.execute('UPDATE Patient SET name=?, issue=?, age=? WHERE id=?', (new_name, new_issue, new_age, patient_id)) conn.commit() # Example usage insert_patient('Ali', 'Fever', 30) insert_patient('Sara', 'Headache', 25) update_patient(1, age=31) delete_patient(2) # Show all patients for row in cursor.execute('SELECT * FROM Patient'): print(row) conn.close()
SQL
Server:
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
MySQL 9.3.0
MariaDB 11.4
MariaDB 11.8
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
PostgreSQL 16
PostgreSQL 17
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