Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- con = sqlite3.connect("kvant.db")
- cursor = con.cursor()
- cursor.execute(""" CREATE TABLE IF NOT EXISTS product
- (id INTEGER PRIMARY KEY AUTOINCREMENT,
- name TEXT,
- type TEXT)
- """)
- cursor.execute(""" CREATE TABLE IF NOT EXISTS place
- (id INTEGER PRIMARY KEY AUTOINCREMENT,
- name TEXT,
- x_cord INTEGER,
- y_cord INTEGER)
- """)
- cursor.execute(""" CREATE TABLE IF NOT EXISTS 'order'
- (id INTEGER PRIMARY KEY AUTOINCREMENT,
- product_id INTEGER,
- place_id INTEGER,
- delivery_time INTEGER,
- FOREIGN KEY (product_id) REFERENCES product (id) ON DELETE CASCADE,
- FOREIGN KEY (place_id) REFERENCES place (id) ON DELETE CASCADE)
- """)
- products = [("Baikal", "Gazirovka"), ("Tarhun", "Gazirovka"), ("Snikers", "Chocolate"), ("Vkusnoteevo", "Milk"), ("Yura", "Tubik")]
- cursor.executemany("INSERT INTO product (name, type) VALUES (? , ?)", products)
- con.commit()
- print(cursor.execute(""" SELECT * FROM product """).fetchall())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement