SQL tutorial-Create Alter and Delete tables |
||||||||||||||
Create , alter, and delete tablesSQL not only provides you the ability to work with the records of a table but also allows you create, delete, and alter a table or queries.
To change the structure of the table such as adding new fields, deleting fields, changing the properties of the fields, you can use ALTER statement. This statement has the following prototype: ALTER TABLE Table-name ADD COLUMN field-name type [constrains] | ALTER COLUMNfield-name type [constrains] | DROP COLUMN field-name; Example: Now we want to change the field ISBN not to allow the user to enter the blank value and to add a new field call PubID that was missed in the previous example. ALTER TABLE TblBook ALTER COLUMN(ISBN TEXT(20) NOT NULL); ALTER TABLE TblBook ADD COLUMN(PubID TEXT);
To delete a table is a simple task. You simply use the DROP TABLE statement followed by the name of table that you want to delete. Example: DROP TABLE TblBook; |
| |||||||||||||
|
||||||||||||||