teslariu

crear_base_resto

Oct 5th, 2022
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import sqlite3
  5.  
  6. conn = sqlite3.connect("resto.db")
  7. cursor = conn.cursor()
  8.  
  9. query = "CREATE TABLE categoria(\
  10.    id INTEGER PRIMARY KEY AUTOINCREMENT,\
  11.    nombre TEXT UNIQUE NOT NULL\
  12.    )"
  13.    
  14. cursor.execute(query)
  15.  
  16. query = "CREATE TABLE platos(\
  17.    id INTEGER PRIMARY KEY AUTOINCREMENT,\
  18.    nombre TEXT UNIQUE NOT NULL,\
  19.    id_categoria INTEGER NOT NULL,\
  20.    FOREIGN KEY(id_categoria) REFERENCES categoria(id)\
  21.    )"
  22.    
  23. cursor.execute(query)
  24.  
  25. conn.close()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment