SQL DELETE Statement
The DELETE Statement in SQL is used to delete existing records from a table. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause.
DELETE FROM table_name WHERE condition;
StudentID | StudentName | ParentsContact | Address | Country | DOB | Section |
Branch |
1 |
Liam | 10101010 | 23 MG road Banglore |
INDIA | 12/06 | A | CSE |
2 | Andrew | 20202020 | 2415 Anthony market str | Germany | 01/02 | A | ISE |
3 | Joshua | 30303030 | 26547 David church road | USA | 18/04 | B | CL |
4 | Ryan | 40404040 | 18 Krishna sq. Banglore |
INDIA | 26/12 | B | EE |
5 | Charles | 50505050 | 878 Eli Berguvsvägen 8 | INDIA | 23/11 | C | ECE |
$sql = "DELETE FROM Student WHERE StudentName='Juan'";
<!DOCTYPE html>
<html lang="en">
<head>
<title>How to use SQL DELETE Statement</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<br>
<br>
<br>
<div class="text-center">
<h1>SQL DELETE Statement</h1>
</div>
<div class="well">
<?php
$connect = mysqli_connect("localhost", "root", "", "school_management");
if($connect === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "DELETE FROM Student WHERE StudentName='Juan'";
if(mysqli_query($connect, $sql)){
echo "<h1>Deleted Record successfully.</h1>";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect);
}
mysqli_close($connect);
?>
</div>
<br>
</div>
</body>
</html>