Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

ALTER TABLE



SQL ALTER TABLE Statement


The SQL ALTER TABLE statement is used to modify an existing table structure. It allows you to add, modify, or drop columns, as well as add or drop constraints like primary keys, foreign keys, and indexes. Here are some common uses of the ALTER TABLE statement:

  1. Adding a Column:


  2. ALTER TABLE table_name
    ADD column_name datatype;


  3. Modifying a Column:


  4. ALTER TABLE table_name
    MODIFY column_name datatype;

  5. Dropping a Column:


  6. ALTER TABLE table_name DROP COLUMN column_name;

  7. Adding a Primary Key Constraint:

  8. ALTER TABLE table_name
    ADD CONSTRAINT constraint_name PRIMARY KEY (column_name);

  9. Dropping a Primary Key Constraint:


  10. ALTER TABLE table_name DROP CONSTRAINT constraint_name;


  11. Adding a Foreign Key Constraint:


  12. ALTER TABLE table_name
    ADD CONSTRAINT constraint_name FOREIGN KEY (column_name)
    REFERENCES other_table (other_column);


  13. Dropping a Foreign Key Constraint:


  14. ALTER TABLE table_name
    DROP CONSTRAINT constraint_name;

  15. Adding an Index:


  16. ALTER TABLE table_name
    ADD INDEX index_name (column_name);


  17. Dropping an Index:

  18. ALTER TABLE table_name
    DROP INDEX index_name;



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java