Merge pull request #5701 from kamranahmedse/dansholds/5700-missing-ddl-subtopic

add DROP table sub-topic
pull/5705/head
dsh 9 months ago committed by GitHub
commit 303e92dceb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 47
      src/data/roadmaps/sql/content/102-ddl/103-drop-table.md
  2. 14411
      src/data/roadmaps/sql/sql.json

@ -0,0 +1,47 @@
# Drop Table
The `DROP TABLE` statement is a Data Definition Language (DDL) operation that is used to completely remove a table from the database. This operation deletes the table structure along with all the data in it, effectively removing the table from the database system.
When you execute the `DROP TABLE` statement, it eliminates both the table and its data, as well as any associated indexes, constraints, and triggers. Unlike the `TRUNCATE TABLE` statement, which only removes data but keeps the table structure, `DROP TABLE` removes everything associated with the table.
## Syntax
In SQL, the `DROP TABLE` statement is quite simple:
```sql
DROP TABLE table_name;
```
In this command, "table_name" refers to the name of the table you wish to remove.
## Example
If you have a table named `Orders` and you want to delete the entire table, you would use:
```sql
DROP TABLE Orders;
```
After executing this statement, the `Orders` table would no longer exist in the database.
## Considerations
- **Irreversible Action**: Unlike `DELETE` and `TRUNCATE`, once a table is dropped, the action cannot be rolled back. Therefore, it should be used with extreme caution.
- **Cascading Effects**: Dropping a table that is referenced by a foreign key constraint will also drop that foreign key relationship. Similarly, any dependent objects like views, stored procedures, or functions that reference the table might be affected.
- **Permissions**: Ensure you have the appropriate permissions to drop the table. Typically, this requires `DROP` privilege on the table.
## Limitations
There are certain conditions and limitations to keep in mind when using `DROP TABLE`:
- **Foreign Key Constraints**: If the table is referenced by foreign keys from other tables, dropping it might require using `CASCADE` to also drop the dependent foreign keys.
- **Replication**: Tables published using transactional or merge replication should be carefully considered before dropping, as this can impact replication.
- **Dependent Objects**: Dropping a table will invalidate any dependent objects such as views, stored procedures, and functions that reference the table. Ensure these are handled appropriately.
For example, if a table `Orders` is referenced by a foreign key in another table `OrderDetails`, dropping `Orders` might require:
```sql
DROP TABLE Orders CASCADE;
```
This ensures that any foreign key relationships are also removed along with the table.

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save