Answers for "python db.sqlite3 create"

SQL
5

python sqlite3 database

import sqlite3

# Create database
conn = sqlite3.connect('tablename.db')
c = conn.cursor()
c.execute('''CREATE TABLE tablename(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, number REAL)''')
conn.commit()
conn.close()

# Insert Values
conn = sqlite3.connect('tablename.db')
c = conn.cursor()
c.execute("INSERT INTO tablename VALUES (?, ?)", (name, number))
conn.commit()
conn.close()

# Read Values
conn = sqlite3.connect('tablename.db')
c = conn.cursor()

for row in c.execute('SELECT * FROM tablename'):
	print(row)

number = [row[2] for row in c.execute('SELECT * FROM tablename')]
conn.close()
Posted by: Guest on June-27-2021
0

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)
Posted by: Guest on April-21-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language