Database Reference
In-Depth Information
TABLE "history" CONSTRAINT "FORN_KEY"FOREIGN KEY
(warehouse_id) REFERENCES warehouse_tbl(warehouse_id) TABLE
"history" CONSTRAINT "FORN_KEY" FOREIGN KEY (warehouse_id)
REFERENCES warehouse_tbl(warehouse_id)
To drop a column from a table, we can use the following statement:
warehouse_db=# ALTER TABLE warehouse_tbl
DROP COLUMN phone_no;
We can then inally verify that the column has been removed from the table by
describing the table again as follows:
warehouse_db=# \d warehouse_tbl
Table "public.warehouse_tbl"
Column | Type | Modifiers
----------------+------------------------+-----------
warehouse_id | integer | not null
warehouse_name | text | not null
year_created | integer |
street_address | text |
city | character varying(100) |
state | character varying(2) |
zip | character varying(10) |
Indexes:
"PRIM_KEY" PRIMARY KEY, btree (warehouse_id)
Referenced by:
TABLE "history" CONSTRAINT "FORN_KEY" FOREIGN KEY
(warehouse_id) REFERENCES warehouse_tbl(warehouse_id) TABLE
"history" CONSTRAINT "FORN_KEY" FOREIGN KEY (warehouse_id)
REFERENCES warehouse_tbl(warehouse_id)
Truncating tables
The TRUNCATE command is used to remove all rows from a table without providing
any criteria. In the case of the DELETE command, the user has to provide the delete
criteria using the WHERE clause. To truncate data from the table, we can use the
following statement:
warehouse_db=# TRUNCATE TABLE warehouse_tbl;
We can then verify that the warehouse_tbl table has been truncated by performing
a SELECT COUNT(*) query on it using the following statement:
warehouse_db=# SELECT COUNT(*) FROM warehouse_tbl;
count
-------
0
(1 row)
 
Search WWH ::




Custom Search