Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 00d7660

Browse files
Database_Interaction script added
1 parent ab8919d commit 00d7660

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import sqlite3
2+
3+
def create_table(connection):
4+
cursor = connection.cursor()
5+
cursor.execute('''CREATE TABLE IF NOT EXISTS employees (
6+
id INTEGER PRIMARY KEY,
7+
name TEXT,
8+
position TEXT,
9+
salary REAL
10+
)''')
11+
connection.commit()
12+
13+
def insert_data(connection, name, position, salary):
14+
cursor = connection.cursor()
15+
cursor.execute("INSERT INTO employees (name, position, salary) VALUES (?, ?, ?)",
16+
(name, position, salary))
17+
connection.commit()
18+
19+
def update_salary(connection, employee_id, new_salary):
20+
cursor = connection.cursor()
21+
cursor.execute("UPDATE employees SET salary = ? WHERE id = ?", (new_salary, employee_id))
22+
connection.commit()
23+
24+
def query_data(connection):
25+
cursor = connection.cursor()
26+
cursor.execute("SELECT * FROM employees")
27+
rows = cursor.fetchall()
28+
29+
print("\nEmployee Data:")
30+
for row in rows:
31+
print(f"ID: {row[0]}, Name: {row[1]}, Position: {row[2]}, Salary: {row[3]}")
32+
33+
if __name__ == "__main__":
34+
database_name = "employee_database.db"
35+
36+
connection = sqlite3.connect(database_name)
37+
print(f"Connected to {database_name}")
38+
39+
create_table(connection)
40+
41+
insert_data(connection, "John Doe", "Software Engineer", 75000.0)
42+
insert_data(connection, "Jane Smith", "Data Analyst", 60000.0)
43+
44+
print("\nAfter Insertions:")
45+
query_data(connection)
46+
47+
update_salary(connection, 1, 80000.0)
48+
49+
print("\nAfter Update:")
50+
query_data(connection)
51+
52+
connection.close()
53+
print(f"Connection to {database_name} closed.")

‎Database_Interaction/README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Database_Interaction
2+
3+
Short description of package/script
4+
5+
- This Script Was simple to setup
6+
- Need import sqlite3
7+
8+
9+
## Setup instructions
10+
11+
12+
Just Need to run this command "pip install sqlite3" then run Databse_Interaction.py file and for running python3 is must be installed!
13+
14+
## Detailed explanation of script, if needed
15+
16+
This Script Is Only for Database_Interaction use only!

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /