From f1fbca6fc92bfce4c8ac66cf6a783b67c52de32f Mon Sep 17 00:00:00 2001 From: Ashutosh Kumar Date: Sat, 11 May 2024 06:33:28 +0530 Subject: [PATCH] Fix alter table query (#5137) * Update 101-alter-table.md Previously : ALTER TABLE tableName ALTER COLUMN columnName TYPE newDataType; results in syntax error Now: ALTER TABLE tableName MODIFY COLUMN columnName newDataType; * Update 101-alter-table.md Added how to drop an primary key * Update src/data/roadmaps/sql/content/102-ddl/101-alter-table.md Co-authored-by: dsh --------- Co-authored-by: Kamran Ahmed Co-authored-by: dsh --- .../roadmaps/sql/content/102-ddl/101-alter-table.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/data/roadmaps/sql/content/102-ddl/101-alter-table.md b/src/data/roadmaps/sql/content/102-ddl/101-alter-table.md index 066d2cdf2..6d8dd0b95 100644 --- a/src/data/roadmaps/sql/content/102-ddl/101-alter-table.md +++ b/src/data/roadmaps/sql/content/102-ddl/101-alter-table.md @@ -46,7 +46,7 @@ To modify the datatype of a column: ```sql ALTER TABLE tableName -ALTER COLUMN columnName TYPE newDataType; +MODIFY COLUMN columnName newDataType; ``` ## Add/Drop Constraints @@ -66,4 +66,10 @@ ALTER TABLE tableName DROP CONSTRAINT constraintName; ``` -In conclusion, `ALTER TABLE` in SQL lets you alter the structure of an existing table. This is a powerful command that lets you dynamically add, modify, and delete columns as well as the constraints placed on them. It ensures you are more flexible in dealing with changing data storage requirements. \ No newline at end of file +To drop PRIMARY KEY: + +```sql +ALTER TABLE table_name +DROP PRIMARY KEY; + +In conclusion, `ALTER TABLE` in SQL lets you alter the structure of an existing table. This is a powerful command that lets you dynamically add, modify, and delete columns as well as the constraints placed on them. It ensures you are more flexible in dealing with changing data storage requirements.