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

create tables in sqlite from python

-- 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)
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 :: seaborn stripplot range 
Python :: literal_eval in python 
Python :: convert image to binary python 
Python :: zip function python 
Python :: Python Program to Sort Words in Alphabetic Order 
Python :: python console 
Python :: length of series pandas 
Python :: python inline if 
Python :: production mode flask 
Python :: how to create a 2d array in python 
Python :: python typing 
Python :: extract specific key values from python dictionary 
Python :: how to run python code in python 
Python :: randint 
Python :: python bin() 
Python :: python string first letter uppercase and second letter in lowercase 
Python :: count TRUE in DF 
Python :: strip plot (normal) 
Python :: django run command from code 
Python :: github3 python 
Python :: discord python application bot 
Python :: numpy.where 
Python :: Implement a binary search of a sorted array of integers Using pseudo-code. 
Python :: python get file ending 
Python :: elif python 
Python :: sum up list python 
Python :: kaspersky 
Python :: selenium wait until 
Python :: what is serializer in django 
Python :: Python Pandas: Create new column out of other columns where value is not null 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =