qertnine.blogg.se

Postgresql alter table
Postgresql alter table













postgresql alter table postgresql alter table

To drop a unique key constraint we use the DROP CONSTRAINT command.įor example, if we want to drop the UNIQUE constraint from the email column by the symbol email_employee_unique we will run the following command. Now, our table will look like the following.ĬONSTRAINT email_employee_unique UNIQUE (email), In the following example we are adding a new column email to the employee table.Īdd constraint "email_employee_unique" unique("email") To ensure that a column contains distinct values we add the UNIQUE constraint. Now we will drop the temp column from the table. Right now the table looks like the following. I added the temp column using the following command. Let the temp column be of boolean data type. Let's say we have a temp column in the employee table and we want to drop it. To drop a column from a table we use the DROP COLUMN command. Let's rename the dateOfBirth column back to birthday and modify the column type from TIMESTAMP to DATE. Let's rename the birthday column to dateOfBirth. To rename a column in PostgreSQL we use the RENAME COLUMN command. Let's modify the birthday column that we added to the employee table by changing its type from DATE to TIMESTAMP. To modify column in PostgreSQL we use the ALTER COLUMN command. Now our table will look like the following. Let's add a new column birthday of date data type. This is how our employee table looks now.ĬONSTRAINT "employeeId_employee_pk" PRIMARY KEY ("employeeId") In the following tutorial we will work with the employee table that we created in the CREATE Table tutorial. In this tutorial we will cover the following. We use the ALTER TABLE table_name command in PostgreSQL to alter tables. In this tutorial we will learn to alter table in PostgreSQL.















Postgresql alter table