DROP TABLE语句用于删除现有表,包括其所有触发器,约束和权限。
ij> DROP TABLE table_name;
假设您在数据库中有一个名为Student的表,以下SQL语句删除名为Student的表。
ij> DROP TABLE Student; 0 rows inserted/updated/deleted
由于如果无涯教程尝试对其进行描述,则已删除该表,因此将出现如下错误
ij> DESCRIBE Student; IJ ERROR: No table exists with the name STUDENT
本节教您如何使用JDBC应用程序在Apache Derby数据库中删除表。
链接:https://www.learnfk.comhttps://www.learnfk.com/derby/apache-derby-drop-table.html
来源:LearnFk无涯教程网
import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class DropTable { public static void main(String args[]) throws Exception { //注册驱动 Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); //创建连接 String URL = "jdbc:derby:sampleDB;create=true"; Connection conn = DriverManager.getConnection(URL); //获取Statement对象 Statement stmt = conn.createStatement(); //执行SQL语句 String query = "DROP TABLE Employees"; stmt.execute(query); System.out.println("Table dropped"); } }
在执行上述程序时,您将获得以下输出-
Table dropped
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)