db icon indicating copy to clipboard operation
db copied to clipboard

Add posibility to drop table `IF EXISTS` and `CASCADE`

Open Tigrov opened this issue 2 years ago • 2 comments

Add two options for dropping a table

  1. IF EXISTS - drop table only if it exists
  2. CASCADE - drop also dependencies cascade

Suggestions for QueryBuilderInterface::dropTable()

  • Change argument string $table to array|string $tables and realize method for list of tables;
  • Add second argument $cascade = false and generate SQL query to drop tables and dependencies cascade;
  • Add new method QueryBuilderInterface::dropTableIfExists() with the same agruments and generate SQL query with IF EXISTS construction.

Tigrov avatar Nov 10 '23 08:11 Tigrov

MSSQL is not supported CASCADE option: https://learn.microsoft.com/sql/t-sql/statements/drop-table-transact-sql?view=sql-server-ver16

Should we throw exception when $cascade is true in MSSQL? Or we need to use tricks, for example: https://stackoverflow.com/a/4858773?

vjik avatar Sep 17 '24 11:09 vjik

In cases when DBMS does not support functionality we use complex queries like https://github.com/yiisoft/db-mssql/blob/eb4e5ef9eb7de1fb340b9c4bb894f921d4cad882/src/DDLQueryBuilder.php#L237

Tigrov avatar Sep 17 '24 14:09 Tigrov