forked from wunnox/python_grundlagen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathU10.2_insert.py
executable file
·37 lines (30 loc) · 1.27 KB
/
U10.2_insert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3
###################################################################
# Uebung:
# Folgende Mitarbeiter müssen noch in die Tabelle "personen" eingefügt werden:
# Name: Schmitz, Peter, P-Nr:81343, Gehalt: 3750, Geburtsdatum: 12.04.1958
# Name: Müller, Hans, P-Nr: 6143, Gehalt: 3650, Geburtsdatum: 22.08.1960
#
###################################################################
#### Lösung: ####
# Verbindung und Cursor erzeugen
connection = sqlite3.connect("firma.db")
cursor = connection.cursor()
cursor.execute(
"CREATE TABLE if not exists personen (name TEXT,vorname TEXT,personalnummer INTEGER PRIMARY KEY,gehalt FLOAT,geburtstag TEXT)")
# Datensatz erzeugen
cursor.execute(
"INSERT INTO personen VALUES ('Schmitz','Peter', 81343, 3750, '12.04.1958')")
cursor.execute(
"INSERT INTO personen VALUES ('Müller','Hans', 6143, 3650, '22.08.1960')")
cursor.execute(
"insert into personen values ('Maier','Hans', 6714, 3500, '15.03.1962')")
cursor.execute(
"insert into personen values ('Muster','Hans',8420,3400,'16.08.1985')")
cursor.execute(
"insert into personen values ('Mertens','Julia', 2297, 3621.5, '30.12.1959')")
# Transaktion bestätigen und Verbindung schliessen
connection.commit()
connection.close()