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

create sqlite table in python

import sqlite3
# it will create a databse with name sqlite.db
connection= sqlite3.connect('sqlite.db')   
Comment

PREVIOUS NEXT
Code Example
Python :: pandas casting into integer 
Python :: bs4 table examples python 
Python :: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. 
Python :: pandas fill missing values with average 
Python :: install python setuptools ubuntu 
Python :: python truncate to integer 
Python :: python if not path exist make path 
Python :: source code of Tortoise and hare algorithm in python 
Python :: numpy replace 
Python :: make a specific column a df index 
Python :: get_terminal_sizee python 
Python :: python async threading 
Python :: python iterate letters 
Python :: rename columns in datarame pandas 
Python :: iterate through 2 strings python 
Python :: sorting pandas dataframe like excel 
Python :: encrypt and decrypt python 
Python :: recursive python program to print numbers from n to 1 
Python :: how to pick a random number in a list python 
Python :: distribution plot python 
Python :: python3 return a list of indexes of a specific character in a string 
Python :: flask debug 
Python :: how do i create a file in specific folder in python 
Python :: how to compare current date to future date pythono 
Python :: set axis plt python 
Python :: natsort python pip install 
Python :: linkedin dynamic scrolling using selenium python 
Python :: python extract thefile name from relative path 
Python :: how to get RGB value from pixel in screen live python 
Python :: sql alchemy engine all tables 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =