Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Base de datos que simula un restaurante. Haremos dos tablas:
- 1) Categorias (entrada, principal, postre)
- 2) Platos (asado, flan, empanadas, sopa)
- """
- import sqlite3
- conn = sqlite3.connect("restaurante.db")
- cursor = conn.cursor()
- query = 'CREATE TABLE categorias(\
- id INTEGER PRIMARY KEY AUTOINCREMENT,\
- nombre TEXT UNIQUE NOT NULL\
- )'
- cursor.execute(query)
- conn.commit()
- query = 'CREATE TABLE platos(\
- id INTEGER PRIMARY KEY AUTOINCREMENT,\
- nombre TEXT UNIQUE NOT NULL,\
- id_categoria INTEGER NOT NULL,\
- FOREIGN KEY(id_categoria) REFERENCES categoria(id)\
- )'
- cursor.execute(query)
- conn.commit()
- conn.close()
Add Comment
Please, Sign In to add comment