Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create sqlite database python

import sqlite3

conn = sqlite3.connect('TestDB.db')  # You can create a new database by changing the name within the quotes
c = conn.cursor() # The database will be saved in the location where your 'py' file is saved

# Create table - CLIENTS
c.execute('''CREATE TABLE CLIENTS
             ([generated_id] INTEGER PRIMARY KEY,[Client_Name] text, [Country_ID] integer, [Date] date)''')
          
# Create table - COUNTRY
c.execute('''CREATE TABLE COUNTRY
             ([generated_id] INTEGER PRIMARY KEY,[Country_ID] integer, [Country_Name] text)''')
        
# Create table - DAILY_STATUS
c.execute('''CREATE TABLE DAILY_STATUS
             ([Client_Name] text, [Country_Name] text, [Date] date)''')
                 
conn.commit()

# Note that the syntax to create new tables should only be used once in the code (unless you dropped the table/s at the end of the code). 
# The [generated_id] column is used to set an auto-increment ID for each record
# When creating a new table, you can add both the field names as well as the field formats (e.g., Text)
Comment

python create sqlite db file

import sqlite3
from sqlite3 import Error


def create_connection(db_file):
    """ create a database connection to a SQLite database """
    conn = None
    try:
        conn = sqlite3.connect(db_file)
        print(sqlite3.version)
    except Error as e:
        print(e)
    finally:
        if conn:
            conn.close()


if __name__ == '__main__':
    create_connection(r"C:sqlitedbpythonsqlite.db")
Code language: Python (python)
Comment

PREVIOUS NEXT
Code Example
Python :: plot circles in matplotlib 
Python :: python print 2d array as table 
Python :: como poner estado a un bot en discord 
Python :: python dictionary get vs setdefault 
Python :: how to access a file from root folder in python project 
Python :: hwo to except every error in python try statemen 
Python :: How to take n space separated Integer in a list in python? 
Python :: django request.data example 
Python :: seaborn factorplot python 
Python :: how to insert values to database with using dictionary in python 
Python :: find each geometry overlap python 
Python :: data types in numpy array 
Python :: openpyxl 
Python :: change xlabel python 
Python :: how to make a python file delete itself 
Python :: split function python 
Python :: target encoder sklearn example 
Python :: remove occurence of character from string python 
Python :: python ide 
Python :: slicing in python list 
Python :: sorted python 
Python :: max python 
Python :: dict comprehensions 
Python :: find and replace subword in word python regex 
Python :: infinite while loop in python 
Python :: recursion python examples 
Python :: NumPy roll Syntax 
Python :: How to change the title of a console app in python 
Python :: python int to byte 
Python :: django annotate 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =