yiisoft / db

Yii Database Library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
134 stars 35 forks source link

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

Open Tigrov opened 1 year ago

Tigrov commented 1 year ago

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()

vjik commented 2 months ago

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?

Tigrov commented 2 months ago

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