632 CHAPTER 28 FROM DATABASES TO DATATYPES (Best web site)

632 CHAPTER 28 FROM DATABASES TO DATATYPES Deleting a Table Deleting, or dropping, a table is accomplished via the DROP TABLEstatement. Its syntax follows: DROP TABLE tbl_name [, tbl_name…] [ CASCADE | RESTRICT ] For example, you could delete your employee table as follows: DROP TABLE employee; You could also simultaneously drop the employee2 and employee3 tables created in previous examples like so: DROP TABLE employee2 employee3; By default, dropping a table removes any constraints, indexes, rules, and triggers that exist for the table specified. However, to drop a table that is referenced by a foreign key (see the REFERENCES section later in the chapter for more information) in another table, or by a view, you must specify the CASCADE parameter, which removes any dependent views entirely. However, it removes only the foreign-key constraint in the other tables, not the tables entirely. Altering a Table Structure You ll find yourself often revising and improving your table structures, particularly in the early stages of development. However, you don t have to go through the hassle of deleting and recreating the table every time you d like to make a change. Rather, you can alter the table s structure with the ALTER statement. With this statement, you can delete, modify, and add columns as you deem necessary. Like CREATE TABLE, the ALTER TABLE statement offers a vast number of clauses, keywords, and options. You can look up the gory details in the PostgreSQL manual on your own. This section offers several examples intended to get you started quickly. Let s begin with adding a column. Suppose you want to track each employee s birth date with the employee table: ALTER TABLE employee ADD COLUMN birthday TIMESTAMPTZ; Whoops! You forgot the NOT NULL clause. You can modify the new column as follows: ALTER TABLE employee ALTER COLUMN birthday SET NOT NULL; Most people don t know what time they were born, so changing the datatype to a DATE would be more appropriate. In previous versions of PostgreSQL, this would have meant going through the trouble of creating a new column, updating it, dropping the old column, and then renaming the new column. Fortunately, as of PostgreSQL 8.0, you can now do it simply, using the ALTER TYPE command: ALTER TABLE employee ALTER COLUMN birthday TYPE DATE; Of course, now that it is a date column, maybe it would be better served to change the name of the column to birthdate. This is done with the RENAME command: ALTER TABLE employee RENAME COLUMN birthday TO birthdate;
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Leave a Reply