turn this er diagram into a python sqlite3 code:
erDiagram
CITY ||--o{ DISTRICT : contains
CITY {
int id
string name
string description
}
DISTRICT {
int id
string name
int population
}
code
CITY ||--|{ LANDMARK : has
LANDMARK {
int id
string name
string type
string description
}
DISTRICT ||--|{ STREET : contains
STREET {
int id
string name
string description
}
LANDMARK }|--|| TOURIST : visits
TOURIST {
int id
string name
string nationality
}
STREET }|--|| VENDOR : located_on
VENDOR {
int id
string name
string goodsSold
}
RIVER ||--|{ BRIDGE : crosses
RIVER {
int id
string name
float length
}
BRIDGE {
int id
string name
int yearBuilt
}
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
import sqlite3
# Create a database connection
conn = sqlite3.connect('city_landmarks.db')
# Create a cursor
c = conn.cursor()
# Create the CITY table
c.execute("""CREATE TABLE CITY (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
description TEXT
)""")
# Create the DISTRICT table
c.execute("""CREATE TABLE DISTRICT (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
population INTEGER
)""")
# Create the LANDMARK table
c.execute("""CREATE TABLE LANDMARK (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
type TEXT,
description TEXT
)""")
# Create the STREET table
c.execute("""CREATE TABLE STREET (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
description TEXT
)""")
# Create the TOURIST table
c.execute("""CREATE TABLE TOURIST (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
nationality TEXT
)""")
# Create the VENDOR table
c.execute("""CREATE TABLE VENDOR (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
goodsSold TEXT
)""")
# Create the RIVER table
c.execute("""CREATE TABLE RIVER (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
length REAL
)""")
# Create the BRIDGE table
c.execute("""CREATE TABLE BRIDGE (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
yearBuilt INTEGER
)""")
# Create the relationships
c.execute("""CREATE TABLE CITY_DISTRICT (
city_id INTEGER,
district_id INTEGER,
PRIMARY KEY (city_id, district_id),
FOREIGN KEY (city_id) REFERENCES CITY (id),
FOREIGN KEY (district_id) REFERENCES DISTRICT (id)
)""")
c.execute("""CREATE TABLE CITY_LANDMARK (
city_id INTEGER,
landmark_id INTEGER,
PRIMARY KEY (city_id, landmark_id),
FOREIGN KEY (city_id) REFERENCES CITY (id),
FOREIGN KEY (landmark_id) REFERENCES LANDMARK (id)
)""")
c.execute("""CREATE TABLE DISTRICT_STREET (
district_id INTEGER,
street_id INTEGER,
PRIMARY KEY (district_id, street_id),
FOREIGN KEY (district_id) REFERENCES DISTRICT (id),
FOREIGN KEY (street_id) REFERENCES STREET (id)
)""")
c.execute("""CREATE TABLE LANDMARK_TOURIST (
landmark_id INTEGER,
tourist_id INTEGER,
PRIMARY KEY (landmark_id, tourist_id),
FOREIGN KEY (landmark_id) REFERENCES LANDMARK (id),
FOREIGN KEY (tourist_id) REFERENCES TOURIST (id)
)""")
c.execute("""CREATE TABLE STREET_VENDOR (
street_id INTEGER,
vendor_id INTEGER,
PRIMARY KEY (street_id, vendor_id),
FOREIGN KEY (street_id) REFERENCES STREET (id),
FOREIGN KEY (vendor_id) REFERENCES VENDOR (id)
)""")
c.execute("""CREATE TABLE RIVER_BRIDGE (
river_id INTEGER,
bridge_id INTEGER,
PRIMARY KEY (river_id, bridge_id),
FOREIGN KEY (river_id) REFERENCES RIVER (id),
FOREIGN KEY (bridge_id) REFERENCES BRIDGE (id)
)""")
# Commit the changes to the database
conn.commit()
# Close the cursor and the connection
c.close()
conn.close()