Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a record from database using Python

Tags:

I have created a Django app and tested the application's performance by populating some 10,0000 records. Now i want to delete it using a python script. Can somebody help me in doing this. This is the script i created to populate data into sql db.

def dumpdata():     for i in range(2,10):         userName = "Bryan"             designation = 'Technician '         employeeID = 2312                  dateOfJoin = '2009-10-10'             EmployeeDetails(userName= "Bryan",designation= 'Technician',employeeID= 2312,dateOfJoin= '2009-10-10').save()  dumpdata()  
like image 988
rv_k Avatar asked Mar 10 '11 10:03

rv_k


People also ask

How do I delete a record in database?

To select a record, click the record selector next to the record, if the record selector is available. To extend or reduce the selection, drag the record selector (if it is available), or press SHIFT+DOWN ARROW or SHIFT+UP ARROW. Press DELETE, select Home > Records > Delete, or press Ctrl+Minus Sign (-).

How do you delete a statement in Python?

The del keyword in python is primarily used to delete objects in Python. Since everything in python represents an object in one way or another, The del keyword can also be used to delete a list, slice a list, delete a dictionaries, remove key-value pairs from a dictionary, delete variables, etc.

How do you delete a table in MySQL using Python?

You can remove an entire table using the DROP TABLE statement. You just need to specify the name of the table you need to delete.

How do I delete a record in MySQL?

If you want to delete a record from any MySQL table, then you can use the SQL command DELETE FROM. You can use this command at the mysql> prompt as well as in any script like PHP.


1 Answers

QuerySet.delete()

EmployeeDetails.objects.filter(...).delete() 
like image 123
Ignacio Vazquez-Abrams Avatar answered Oct 15 '22 11:10

Ignacio Vazquez-Abrams