ALTER statement different SQL Queries you need to modify objects

You can modify database objects using ALTER. The database objects are related to data, so you must be careful enough to alter any objects. Why I am stressing is the mistake you made causes to lose all the data.

sql alter add columns

Given below are best SQL Queries on SQL ALTER. These are useful to use in your projects.

SQL ALTER statement

The objects on which ALTER you can use are TABLE, INDEX, FUNCTION, MASK, TABLESPACE, SERVER, SEQUENCE, and THRESHOLD

ALTER TABLE Add Column

ALTER TABLE table_name ADD COLUMN name_of_column;

In the above SQL query, you are adding new column name for an existing Table. Also, you can modify column data types.

ALTER INDEX

ALTER INDEX index_name REGENERATE;

You cannot add new Index on existing Table. When you want to add new index, you need to drop existing ones and to create new ones.

The REGENERATE specifies that the index will be regenerated or rebuild. This command is useful if an index already created.

ALTER DATABASE

ALTER DATABASE database_name new_buffer_pool;

You can modify database parameters. This is to add more buffer-pools. Also, you can add storage or drop storage.

ALTER FUNCTION

ALTER FUNCTION GET_TABLE
    RESTRICT CARDINALITY 10000;

In the above SQL, you can modify the parameters given in the user defined functions.

The Bottom Line

The ALTER statement in production region only Admins will handle. In test regions, all the developers have access to do their research.

References

Related Posts

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.