Hsqldb 简明教程
HSQLDB - Drop Table
删除一个现有的 HSQLDB 表非常容易。但是,在删除任何现有的表时,您需要非常小心,因为删除表后任何丢失的数据都无法恢复。
It is very easy to drop an existing HSQLDB table. However, you need to be very careful while deleting any existing table as any data lost will not be recovered after deleting a table.
Syntax
以下是用来删除 HSQLDB 表的通用 SQL 语法。
Following is a generic SQL syntax to drop a HSQLDB table.
DROP TABLE table_name;
Example
我们考虑一个示例,从 HSQLDB 服务器删除名为 employee 的表。以下是用来删除名为 employee 的表的查询。
Let us consider an example to drop a table named employee from the HSQLDB server. Following is the query to drop a table named employee.
DROP TABLE employee;
执行以上查询后,您将收到以下输出 −
After execution of the above query, you will receive the following output −
(0) rows effected
HSQLDB – JDBC Program
以下是用于从 HSQLDB 服务器删除名为 employee 的表的 JDBC 程序。
Following is the JDBC program used to drop the table employee from the HSQLDB server.
将以下代码另存为 DropTable.java 文件。
Save the following code into DropTable.java file.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class DropTable {
public static void main(String[] args) {
Connection con = null;
Statement stmt = null;
int result = 0;
try {
Class.forName("org.hsqldb.jdbc.JDBCDriver");
con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/testdb", "SA", "");
stmt = con.createStatement();
result = stmt.executeUpdate("DROP TABLE employee");
}catch (Exception e) {
e.printStackTrace(System.out);
}
System.out.println("Table dropped successfully");
}
}
您可以使用以下命令启动数据库。
You can start the database using the following command.
\>cd C:\hsqldb-2.3.4\hsqldb
hsqldb>java -classpath lib/hsqldb.jar org.hsqldb.server.Server --database.0
file:hsqldb/demodb --dbname.0 testdb
使用以下命令编译并执行以上程序。
Compile and execute the above program using the following command.
\>javac DropTable.java
\>java DropTable
在执行上述命令之后,您将收到以下输出−
After execution of the above command, you will receive the following output −
Table dropped successfully