KnowledgeBoat Logo
|

Informatics Practices

What is the purpose of ALTER TABLE command ? Can you add new columns with constraints such as NOT NULL ? Give example to justify your answer.

SQL Queries

28 Likes

Answer

The ALTER TABLE command is used to change definitions of existing tables. It is used to add columns, integrity constraints and redefine a column (datatype, size, default value) in a table.

Yes, we can add new columns with constraints such as NOT NULL, which ensures that a column must always contain a value (i.e., cannot be empty or null).

For example, to add a new column tel_number with the NOT NULL constraint in the Empl table, the statement is:

ALTER TABLE Empl
ADD COLUMN(tel_number integer NOT NULL);

Answered By

1 Like


Related Questions