xxxxxxxxxx
import sqlite3
# Connecting to sqlite
# connection object
connection_obj = sqlite3.connect('geek.db')
# cursor object
cursor_obj = connection_obj.cursor()
# Drop the GEEK table if already exists.
cursor_obj.execute("DROP TABLE IF EXISTS GEEK")
# Creating table
table = """ CREATE TABLE GEEK (
Email VARCHAR(255) NOT NULL,
First_Name CHAR(25) NOT NULL,
Last_Name CHAR(25),
Score INT
); """
cursor_obj.execute(table)
print("Table is Ready")
# Close the connection
connection_obj.close()
xxxxxxxxxx
import sqlite3
# it will create a databse with name sqlite.db
connection= sqlite3.connect('sqlite.db')
cursor = connection.cursor()
# table name = Website
# Table fields are
# Post: Text type
# Autor: Text type
# Views: Real type
cursor.execute('''CREATE TABLE Website
(Post text, Autor text, Views real)''')
# Save (commit) the changes
connection.commit()
# close connection
connection.close()
xxxxxxxxxx
import sqlite3
# it will create a databse with name sqlite.db
connection= sqlite3.connect('sqlite.db')
xxxxxxxxxx
-- projects table
CREATE TABLE IF NOT EXISTS projects (
id integer PRIMARY KEY,
name text NOT NULL,
begin_date text,
end_date text
);
-- tasks table
CREATE TABLE IF NOT EXISTS tasks (
id integer PRIMARY KEY,
name text NOT NULL,
priority integer,
project_id integer NOT NULL,
status_id integer NOT NULL,
begin_date text NOT NULL,
end_date text NOT NULL,
FOREIGN KEY (project_id) REFERENCES projects (id)
);
Code language: SQL (Structured Query Language) (sql)