+1-617-874-1011 (US)

  +44-117-230-1145 (UK)



Delete data in MySQL

Similarly as you supplement records into tables, you can erase records from a table utilizing the SQL DELETEstatement. It is regularly utilized in conjugation with the WHERE provision to erase just those records that matches explicit criteria or condition.

The essential grammar of the DELETE proclamation can be given with:

Erase FROM table_name WHERE column_name=some_value

We should make a SQL question utilizing the DELETE proclamation and WHERE provision, after that we will execute this inquiry through passing it to the PHP mysqli_query() capacity to erase the tables records. Think about the accompanying people table inside the demo database:

The PHP code in the accompanying model will erase the records of those people from the people table whose first_name is equivalent to John.

Delete Query - Procedural Method :

$mysqli = new mysqli("localhost", "root", "", "Mydb");
if( $mysqli === false ){
die("ERROR: Could not connect. " . $mysqli->connect_error);
}
$sql = "DELETE FROM Data WHERE ID=201";
if($mysqli->query($sql) === true){
echo "Record was deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. "
. $mysqli->error;
}
$mysqli->close();

Table After Updation

delete database

Delete Query - PDO Method :

try{
$pdo = new PDO("mysql:host=localhost;
dbname=Mydb", "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
die("ERROR: Could not connect. " . $e->getMessage());
}
try{
$sql = "DELETE FROM Data WHERE ID=201";
$pdo->exec($sql);
echo "Record was deleted successfully.";
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. "
. $e->getMessage());
}
unset($pdo);

Table After Updation

delete database

Keywords: MYSQL Tutorials, Data Relations homework help, SQL homework help, SQL project Help, Oracle Homework Help, XML homework help, XML and Relational Algebra assignment help, SQL Queries and Updates homework assignment help, XML Queries and Transformations tutoring help, Relational Database Design concept, Higher-Level Design help in UML and ERD, Data Warehousing and Data Mining, help with SQL 2008 database, support for Database help, Microsoft access and mysql database programmer, database development and xml database support, homework helper for asp database and uml modeling, uml sequence diagram and uml class diagram, database design development and software SQL server 2008.