![]() Generailly, to add a constraint to a table, you use ALTER TABLE ADD CONSTRAINT statement: ALTER TABLE table_nameĪDD CONSTRAINT constraint_name constraint_definition Code language: SQL (Structured Query Language) ( sql ) To add a CHECK constraint, you use ALTER TABLE ADD CHECK statement: ALTER TABLE table_nameĪDD CHECK expression Code language: SQL (Structured Query Language) ( sql ) To change the NOT NULL constraint, you use ALTER TABLE ALTER COLUMN statement: ALTER TABLE table_name Code language: SQL (Structured Query Language) ( sql ) To change a default value of the column, you use ALTER TABLE ALTER COLUMN SET DEFAULT or DROP DEFAULT: ALTER TABLE table_name TO new_column_name Code language: SQL (Structured Query Language) ( sql ) To rename a column, you use the ALTER TABLE RENAME COLUMN TO statement: ALTER TABLE table_name To drop a column from a table, you use ALTER TABLE DROP COLUMN statement: ALTER TABLE table_nameĭROP COLUMN column_name Code language: SQL (Structured Query Language) ( sql ) ![]() To add a new column to a table, you use ALTER TABLE ADD COLUMN statement: ALTER TABLE table_nameĪDD COLUMN column_name datatype column_constraint Code language: SQL (Structured Query Language) ( sql ) PostgreSQL provides you with many actions: The following illustrates the basic syntax of the ALTER TABLE statement: ALTER TABLE table_name action Code language: SQL (Structured Query Language) ( sql ) To change the structure of an existing table, you use PostgreSQL ALTER TABLE statement. Introduction to PostgreSQL ALTER TABLE statement Summary: in this tutorial, you will learn how to use the PostgreSQL ALTER TABLE statement to modify the structure of a table. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |