Skip to content

Commit 3abc0ae

Browse files
committed
Creating databases using sqlite3
1 parent 48d38a9 commit 3abc0ae

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

employees.db

2 KB
Binary file not shown.

python_sqlite.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sqlite3
2+
3+
4+
# Creating a connection sqlite database, it will create .db file in file system
5+
# other way to create is using memory, so database will be in memory (RAM)
6+
# conn = sqlite3.connect(':memory:')
7+
conn = sqlite3.connect('employees.db')
8+
9+
# To get cursor to the database
10+
c = conn.cursor()
11+
12+
# Create table using cursor
13+
#c.execute("""CREATE TABLE employees
14+
# (
15+
# first test,
16+
# last text,
17+
# pay integer
18+
# )""")
19+
20+
#c.execute("""INSERT INTO employees VALUES ('sheldon', 'cooper', '50000')""")
21+
22+
c.execute("SELECT * FROM employees WHERE last='cooper'")
23+
24+
print(c.fetchone())
25+
26+
# Always use conn.commit after execute statement
27+
conn.commit()
28+
29+
# always good to close a connection
30+
conn.close()

0 commit comments

Comments
 (0)