File size: 690 Bytes
fe612fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import streamlit as st
import sqlite3

st.title("Task 1: Create a Database and Tables")

db_name = st.text_input("Enter database name:", "example.db")
table_name = st.text_input("Enter table name:", "students")
columns = st.text_area("Define columns (e.g., id INTEGER PRIMARY KEY, name TEXT):")

if st.button("Create Database and Table"):
    try:
        conn = sqlite3.connect(db_name)
        cursor = conn.cursor()
        cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} ({columns})")
        conn.commit()
        st.success(f"Table '{table_name}' created in database '{db_name}'.")
    except Exception as e:
        st.error(f"Error: {e}")
    finally:
        conn.close()