create table sqlite python

Solutions on MaxInterview for create table sqlite python by the best coders in the world

showing results for - "create table sqlite python"
Emiliano
28 Aug 2019
1CREATE TABLE IF NOT EXISTS some_table (id INTEGER PRIMARY KEY AUTOINCREMENT, ...);
2
Lorenzo
07 Jan 2017
1
2            
3                
4            
5         import sqlite3
6from sqlite3 import Error
7
8
9def create_connection(db_file):
10    """ create a database connection to the SQLite database
11        specified by db_file
12    :param db_file: database file
13    :return: Connection object or None
14    """
15    conn = None
16    try:
17        conn = sqlite3.connect(db_file)
18        return conn
19    except Error as e:
20        print(e)
21
22    return conn
23
24
25def create_table(conn, create_table_sql):
26    """ create a table from the create_table_sql statement
27    :param conn: Connection object
28    :param create_table_sql: a CREATE TABLE statement
29    :return:
30    """
31    try:
32        c = conn.cursor()
33        c.execute(create_table_sql)
34    except Error as e:
35        print(e)
36
37
38def main():
39    database = r"C:\sqlite\db\pythonsqlite.db"
40
41    sql_create_projects_table = """ CREATE TABLE IF NOT EXISTS projects (
42                                        id integer PRIMARY KEY,
43                                        name text NOT NULL,
44                                        begin_date text,
45                                        end_date text
46                                    ); """
47
48    sql_create_tasks_table = """CREATE TABLE IF NOT EXISTS tasks (
49                                    id integer PRIMARY KEY,
50                                    name text NOT NULL,
51                                    priority integer,
52                                    status_id integer NOT NULL,
53                                    project_id integer NOT NULL,
54                                    begin_date text NOT NULL,
55                                    end_date text NOT NULL,
56                                    FOREIGN KEY (project_id) REFERENCES projects (id)
57                                );"""
58
59    # create a database connection
60    conn = create_connection(database)
61
62    # create tables
63    if conn is not None:
64        # create projects table
65        create_table(conn, sql_create_projects_table)
66
67        # create tasks table
68        create_table(conn, sql_create_tasks_table)
69    else:
70        print("Error! cannot create the database connection.")
71
72
73if __name__ == '__main__':
74    main()Code language: Python (python)
Joséphine
16 Jun 2016
1         import sqlite3
2from sqlite3 import Error
3
4
5def create_connection(db_file):
6    """ create a database connection to the SQLite database
7        specified by db_file
8    :param db_file: database file
9    :return: Connection object or None
10    """
11    conn = None
12    try:
13        conn = sqlite3.connect(db_file)
14        return conn
15    except Error as e:
16        print(e)
17
18    return conn
19
20
21def create_table(conn, create_table_sql):
22    """ create a table from the create_table_sql statement
23    :param conn: Connection object
24    :param create_table_sql: a CREATE TABLE statement
25    :return:
26    """
27    try:
28        c = conn.cursor()
29        c.execute(create_table_sql)
30    except Error as e:
31        print(e)
32
33
34def main():
35    database = r"C:\sqlite\db\pythonsqlite.db"
36
37    sql_create_projects_table = """ CREATE TABLE IF NOT EXISTS projects (
38                                        id integer PRIMARY KEY,
39                                        name text NOT NULL,
40                                        begin_date text,
41                                        end_date text
42                                    ); """
43
44    sql_create_tasks_table = """CREATE TABLE IF NOT EXISTS tasks (
45                                    id integer PRIMARY KEY,
46                                    name text NOT NULL,
47                                    priority integer,
48                                    status_id integer NOT NULL,
49                                    project_id integer NOT NULL,
50                                    begin_date text NOT NULL,
51                                    end_date text NOT NULL,
52                                    FOREIGN KEY (project_id) REFERENCES projects (id)
53                                );"""
54
55    # create a database connection
56    conn = create_connection(database)
57
58    # create tables
59    if conn is not None:
60        # create projects table
61        create_table(conn, sql_create_projects_table)
62
63        # create tasks table
64        create_table(conn, sql_create_tasks_table)
65    else:
66        print("Error! cannot create the database connection.")
67
68
69if __name__ == '__main__':
70    main()Code language: Python (python)
queries leading to this page
make tables sqlite pythonsqlite make new database pythonhow to connect the table from python to sqlite3create sqlite database pythoncreate an sqlite database pythoncreate table if not exists sqlite3sqlite3 pythoncreate table sql cmdcreate table from api data python sqlite3how to create table with sqlite python python script to create sqlite databasepython code to create sqlite databasecreate sqlite in pythoncreate sqlite table pytohncreate table sqlite pythongcreate a table in sqlite3 pythonsqlite3 create table and database pythonsqlite3 python create an databasepython sqlite create database sqlite3 python create tablepython sql server create table if not existssqlite3 create table pythonpython sqlite3 create table if not existssqlite in python3 create tableif statement with sqlite not existscreate new table sqlite pythonsqlite python creat tablesqlite create table if not exists pythoncreate or ignore table sqlite3 pythonsqlite create table if not exists in javacreate table if not exists error sqlite3sqlite create table if not existssqlite create if not exists pythonhow to make a sqlite database in pythonsqlite3create table from another tablesqlite3 python create table if dosent existcreate sqlite3 table pythonsqlite3 python create tablescreate table in sqlite3 pythoncreate table sqlite pythoncreate new sqlite database pythonsqlite python create tablesqlite3 linking tables pythonpython sqlite3 create database 5cpython sqlite3 create databasesqlite3 create table from another tablepython sqlite3 create table only if database existssqlite create db pythonpython sqlite dont create tablesqlite3 python create databasehow to create sqlite database in pythonmaking a table in pythoncreate an sqlite database with pythonsqlite table if not existspython create sqlite database if not existshow to create a database with sqllite with pythoncreating a table in sqlite3 pythonsqlite new tablehow to create a table in sqlite using pythonmysql python create table if not exist sqlitepython create sqlite databasesqlite3 create table if not existssqlite3 create table if not exists pythoncreat table if doesnt exist python sqlite3python create table sqlitehow to create a table in sqlite3 pythoncreate table if not exists sqlite pythonpython sqlite create table if not existspython create table if not exists sqlite3how to create sql table in python sqlite3if not exist create sqlite file pythonhow to create database in python sqlite3create table sqlite python sqlalchemypython sqlte create database with tablesqlite3 python sql create table if not existshow to create table in sqlite pythonsqlite if not exists create tablepython sqlite creat table codehow to create table sqlite3 pythonmaking a new database sqlite pyhtonsqkite3 python create tablecreate table sqlite3 pythonpython sqlite make tablecreate table if not exists sqlitesqlite create table if not existcreate sqlite table pythoncreate sqlite3 database in pythonsqlite create table pythoncreate database sqlite pyhtonpython create sqlite database with tablespython sqlite create tablepython create table sqlite3python create a sqlite database store dataframe as a tablehow to create sqllite db in pythonsqlite3 python create table if not existscreate a sqlite database pythonpython sqlite3 create tablehow to create table in sqlite3 pythoncreate sqlite database in pythoncreate table sqlite python