-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrop_table.html
More file actions
129 lines (115 loc) · 3.8 KB
/
Copy pathdrop_table.html
File metadata and controls
129 lines (115 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MySQL Drop Table Query</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #2a5298, #1e3c72); /* Updated background */
color: #fff;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.container {
background: rgba(0, 0, 0, 0.25); /* Updated background for the container */
border-radius: 20px;
padding: 30px;
width: 100%;
max-width: 600px;
text-align: center;
backdrop-filter: blur(12px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
overflow: hidden;
}
h1 {
font-size: 2.5rem;
margin-bottom: 20px;
color: #f7e9dd;
text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
}
pre {
background: rgba(0, 0, 0, 0.3);
padding: 20px;
border-radius: 15px;
text-align: left;
overflow-x: auto;
white-space: pre-wrap;
font-family: 'Courier New', Courier, monospace;
color: #ffdfa0;
margin-bottom: 20px;
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}
.content {
margin: 20px 0;
text-align: left;
line-height: 1.8;
}
.content h3 {
color: #f7e9dd;
margin-bottom: 10px;
}
.content p, .content ol {
color: #e0e0e0;
}
.content ol {
padding-left: 20px;
}
button {
padding: 12px 25px;
background: #2a5298;
color: #fff;
border: none;
border-radius: 30px;
cursor: pointer;
font-size: 1.1rem;
transition: background 0.3s, transform 0.2s;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
button:hover {
background: #1e3c72;
transform: scale(1.05);
}
</style>
</head>
<body>
<div class="container">
<h1>MySQL Drop Table Query</h1>
<pre><code>import mysql.connector
# Establish connection to MySQL
mydb = mysql.connector.connect(host="localhost", user="root", password="root",database="school")
mycursor = mydb.cursor()
# Execute the DROP TABLE query
mycursor.execute("DROP TABLE students")
# Fetch and print all records
for x in mycursor:
print(x)</code></pre>
<div class="content">
<h3>Explanation:</h3>
<ol>
<li>Import the <strong>mysql.connector</strong> module to interact with the MySQL server.</li>
<li>Establish a connection to the MySQL server using <code>mysql.connector.connect()</code>, providing the host, username, and password.</li>
<li>Create a cursor object to execute SQL queries.</li>
<li>Execute the <strong>DROP TABLE</strong> query using <code>mycursor.execute("DROP TABLE students")</code> to remove the <code>students</code> table from the database.</li>
<li>Use a <code>for</code> loop to attempt to fetch and print any records returned by the query, though in the case of <code>DROP TABLE</code>, there are no records returned.</li>
</ol>
<h3>Key Points:</h3>
<ul>
<li><strong>DROP TABLE students</strong>: Deletes the <code>students</code> table from the database.</li>
<li>The <code>DROP TABLE</code> command is irreversible; once the table is dropped, all data and structure are lost.</li>
<li>No results are returned after dropping the table, so the <code>for</code> loop won't print anything in this case.</li>
<li>The cursor object allows you to interact with the database and execute queries.</li>
</ul>
</div>
</div>
</body>
</html>