SQLite CRUD operations

  1. SQLite CRUD operations

The SQLite CRUD operations include four important operations:

  • Create
  • Retrieve
  • Update
  • Delete

 

Don't use plagiarized sources. Get Your Custom Essay on
SQLite CRUD operations
Just from $13/Page
Order Essay
  1. Create

This operation involves inserting a new row in a SQlite database table.  To create a new row, follow the following simple guidelines:

import sqlite3

db=sqlite3.connect(‘studentdb’)

qry=”insert into Studentsmarks (name, age, marks) values(‘Ranjha’, 20, 50);”

try:

    cur=db.cursor()

    cur.execute(qry)

    db.commit()

    print (“Marks added successfully“)

except:

    print (“error in operation”)

    db.rollback()

db.close()

 

  1. Retrieve

This operation involves retrieving a particular row or the entire database table information using the fetchone () and fetchall () methods respectively.

To fetch a single query:

import sqlite3

db=sqlite3.connect(‘studentdb’)

sql=”SELECT * from Studentsmarks;”

cur=db.cursor()

cur.execute(sql)

while True:

    record=cur.fetchone()

    if record==None:

        break    print (record)

db.close()

 

To fetch all database queries:

 

  1. Update

This operation involves altering the information in the database table.  Using this operation you can be able to update any row or the entire table information. This operation works with conditions. For example, in the following code, we are going to update the query where 

import sqlite3

db=sqlite3.connect(‘studentdb’)

qry=”update Studentsmarks set age=? where name=?;”

try:

    cur=db.cursor()

    cur.execute(qry, (19,’Shamir’))

    db.commit()

    print(“record updated successfully”)

except:

    print(“error in operation”)    db.rollback()

db.close()

  1. Delete

This operation allows you to drop a particular entry in the database table. You can drop a particular row or drop the entire table. For instance, in the following code, we are going to drop the query where

import sqlite3

db=sqlite3.connect(‘test.db’)

qry=”DELETE from student where name=?;”

try:

    cur=db.cursor()

    cur.execute(qry, (‘Bill’,))

    db.commit()

    print(“student deleted successfully”)

except:

    print(“error in operation”)

    db.rollback()

db.close()

How to place an order?

Take a few steps to place an order on our site:

  • Fill out the form and state the deadline.
  • Calculate the price of your order and pay for it with your credit card.
  • When the order is placed, we select a suitable writer to complete it based on your requirements.
  • Stay in contact with the writer and discuss vital details of research.
  • Download a preview of the research paper. Satisfied with the outcome? Press “Approve.”

Feel secure when using our service

It's important for every customer to feel safe. Thus, at University Study, we take care of your security.

Financial security You can safely pay for your order using secure payment systems.
Personal security Any personal information about our customers is private. No other person can get access to it.
Academic security To deliver no-plagiarism samples, we use a specially-designed software to check every finished paper.
Web security This website is protected from illegal breaks. We constantly update our privacy management.

Get assistance with placing your order. Clarify any questions about our services. Contact our support team. They are available 24\7.

Still thinking about where to hire experienced authors and how to boost your grades? Place your order on our website and get help with any paper you need. We’ll meet your expectations.

Order now Get a quote

error: Content is protected !!
Open chat
1
Need assignment help? You can contact our live agent via WhatsApp using +1 718 717 2861

Feel free to ask questions, clarifications, or discounts available when placing an order.

Order your essay today and save 30% with the discount code STUDY