Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add posibility to drop table IF EXISTS and CASCADE #773

Open
Tigrov opened this issue Nov 10, 2023 · 2 comments · May be fixed by #880
Open

Add posibility to drop table IF EXISTS and CASCADE #773

Tigrov opened this issue Nov 10, 2023 · 2 comments · May be fixed by #880
Milestone

Comments

@Tigrov
Copy link
Member

Tigrov commented Nov 10, 2023

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 Tigrov added this to the 2.0.0 milestone Nov 22, 2023
@vjik vjik linked a pull request Sep 17, 2024 that will close this issue
@vjik
Copy link
Member

vjik commented Sep 17, 2024

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
Copy link
Member Author

Tigrov commented Sep 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants