AddTables_pgsAdmin1.htm

 Ref: pgAdminIII

Objectives :

  • Create a DB/Table using pgAdminIII.exe
  • data type serial
  • creating a primary key.

Location of pgAdminIII

Click On the exe file:

Connect to database

Login pwd postgre_manas9

Right click on the PostgreSQL-version(localhost:5432)

You may create a database :

Expand the tree, to add a table in this database, right click on the table objectt.

The data types serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases). In the current implementation, specifying:
CREATE TABLE tablename (
    colname SERIAL
);

is equivalent to specifying:

CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
    colname integer NOT NULL DEFAULT 
         nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq 
OWNED BY tablename.colname;

Thus, we have created an integer column and arranged for its default values to be assigned from a sequence generator. A NOT NULL constraint is applied to ensure that a null value cannot be inserted. (In most cases you would also want to attach a UNIQUE or PRIMARY KEY constraint to prevent duplicate values from being inserted by accident, but this is not automatic.) Lastly, the sequence is marked as "owned by" the column, so that it will be dropped if the column or table is dropped.

 

Creating Constraint

SQL code

:

-- Table: "pgsEmp1"
-- DROP TABLE "pgsEmp1";
CREATE TABLE "pgsEmp1"
(
eid serial NOT NULL,
fname text,
lname text,
job text,
CONSTRAINT eid_pk PRIMARY KEY (eid)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "pgsEmp1"
OWNER TO manas237;
 

Dropping and adding new column before entering the data

Deleting a column , note column name "manas"deleted.

Adding columns

 You may Delete an object like table using this GUI. The image below shows that a table "pgsEmp1" was dropped and replaced with a new table with primary key

CREATE TABLE emp1
(
eid serial,
fname varchar(32),
lname varchar(32),
address varchar(100),
manager varchar(32),
CONSTRAINT emp1_pk PRIMARY KEY(eid)

);

Click On view all rows

 

Note the view of the table emp1, when you are creating the table, "serial" data type will add the integer value as auto increment , and you don't have to manually type it.

Start entering the data, and then click on save image

Code: pdo_pgsql3.txt