Python Delete Records in My SQL Table Training

Python – Delete Records in My. SQL Table Training Division - LK Domain Registry

Introduction • This module guides you on how to issue a SQL DELETE (with WHERE) command from Python application to delete records in My. SQL table. • You may need to delete one or more records in a table and it is necessary to provide a condition to identify which record to be deleted. 2

• For an example in the ‘personal’ table of your ‘student’ database, assume that you need to delete details of the student with index number ‘ 016’. • You can achieve this with the SQL query below, DELETE from personal WHERE indexno = ‘ 016’ 3

• Complete code to delete the student with index number 016. 4

• Save above code as dbdelete 1 and run it. • Upon executing above code, it will prompt you to enter index number of the student that you want to delete. • After successfully deleting the record it will output the number of records that was deleted from the table. 5

DELETE commands do be use carefully • Please DO NOT use any of the following commands now. It will destroy your data. You will use these commands in future modules. 1. TRUNCATE TABLE personal Delete all records of the table 2. ALTER TABLE personal DROP COLUMN indexno Delete entire column indexno 3. DROP TABLE personal Delete entire table personal 4. DROP DATABASE student Delete entire database student 6

Thank You! training@nic. lk 7
- Slides: 7