teslariu

resto

Nov 27th, 2021 (edited)
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Base de datos que simula un restaurante. Haremos dos tablas:
  5. 1) Categorias (entrada, principal, postre)
  6. 2) Platos (asado, flan, empanadas, sopa)
  7. """
  8.  
  9. import sqlite3
  10.  
  11. conn = sqlite3.connect("restaurante.db")
  12.  
  13. cursor = conn.cursor()
  14.  
  15. query = 'CREATE TABLE categorias(\
  16.     id INTEGER PRIMARY KEY AUTOINCREMENT,\
  17.     nombre TEXT UNIQUE NOT NULL\
  18.     )'
  19.    
  20. cursor.execute(query)
  21. conn.commit()
  22.  
  23. query = 'CREATE TABLE platos(\
  24.     id INTEGER PRIMARY KEY AUTOINCREMENT,\
  25.     nombre TEXT UNIQUE NOT NULL,\
  26.     id_categoria INTEGER NOT NULL,\
  27.     FOREIGN KEY(id_categoria) REFERENCES categoria(id)\
  28.     )'
  29.    
  30. cursor.execute(query)
  31. conn.commit()
  32. conn.close()
RAW Paste Data