DEV Community

loading...

Day 27 Of 100DaysOfCode : Simple Code Using Database And SQL

iamdurga profile image Durga Pokharel ・2 min read

This is my 27 day of #100DayOfCode and #python. Today I did some code on class inheritance with the help of goggle and textbook of coursera. Learned Database on python. In database on python I learned to make simple database table with the help of DB Browser.

Here is some database today I learned from coursera.

Simple Database And SQL

A database is a file that is organized for storing data. Most databases are organized like a dictionary in the sense that they map from keys to values. The biggest difference is that the database is on disk (or other permanent storage), so it persists after the program ends. Because a database is stored on permanent storage, it can store far more data than a dictionary, which is limited to the size of the memory in the computer.

import sqlite3

conn = sqlite3.connect("example.db")
Enter fullscreen mode Exit fullscreen mode

The code to create a database file and a table named Tracks with two columns in the database is given above. The connect operation makes a “connection” to the database stored in the file in the current directory.

c = conn.cursor()

#create table
c.execute("""CREATE TABLE Users 
(Name variable(128), sname, person)""")
Enter fullscreen mode Exit fullscreen mode

A cursor is like a file handle that we can use to perform operations on the data stored in the database. Calling cursor() is very similar conceptually to calling open() when dealing with text files. In above code we can create table name Users having the two column with name and person.

Discussion (1)

pic
Editor guide
Collapse
otumianempire profile image
Otu Michael

Download sqlite-browser to help you manage the data easily.