![]() ![]() ALTER TABLE EMPLOYEE.Salary DROP COLUMN IsActive Use below query to remove a column from existing table. ALTER table EMPLOYEE.Salary add column IsActive BOOLEAN NOT NULL To drop a column Remember that BOOLEAN is different than BIT in PostgreSQL. You can set default value for boolean type as True, true, 'yes','y', '1', False, false, 'no','n','0' To add new columnīelow query will add a column IsActive of boolean type and set it as NOT NULL. ALTER TABLE EMPLOYEE.Salary ALTER COLUMN IsActive SET DEFAULT True ) To rename table name ALTER TABLE EMPLOYEE.PersonalDetails RENAME TO personĪbove query will rename PersonalDetails table to person To modify datatype of a column ALTER table EMPLOYEE.PersonalDetails ALTER column Address type varchar(500) ALTER table to set default valueīelow query will set default constrant with column IsActive and set default value to true. Adding reference to another table Create Table EMPLOYEE.Salary (ĮmployeeID INT references EMPLOYEE.PersonalDetails(ID) NOTE: Please remember that semi colon INT GENERATED ALWAYS AS IDENTITYĪbove command will create a column "ID" with identity to generate always. By default identity starts from 1 and increment by 1. ID INT GENERATED ALWAYS AS IDENTITY Primary Key, Create database CREATE DATABASE EMPLOYEEDB Drop database DROP DATABASE EMPLOYEEDB Create schema CREATE SCHEMA EMPLOYEE Drop schema DROP SCHEMA EMPLOYEE Drop schema with all tables DROP SCHEMA EMPLOYEE CASCADE Create table Create Table EMPLOYEE.PersonalDetails ( I will discuss this in detail in next article. I have also noticed that Postgres is case-sensitive and by default it takes lower case means if I write simple query to create a schema ike below, it will create it in lower case like employee.īut if I want my schema to show something like EMPLOYEE, then I should write it like below Postgres queries are similar to SQL except few. In this article I have enlisted common commands in PostgreSQL like Create, Alter, Drop etc. This article enlist common daily use queries in PostgreSQL like Create, Alter, Drop etc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |