Breaking News

Script for Database (How to update structure of table)

Example the table of database is IDENTITY :

CREATE TABLE IDENTITY(
NAMES VARCHAR(50),
AGE INTEGER,
ADDRESS VARCHAR(100));


This is script for update table, how to delete field, add field and update type of field:
  • Delete field
This script will delete AGE field from IDENTITY table:
ALTER TABLE IDENTITY
       DROP COLUMN AGE;

  • Add field
This script will add CODE field with INTEGER type, LENGTH = 5; from IDENTITY table:
ALTER TABLE IDENTITY
       ADD COLUMN CODE INT(5) ;

  • Update type of field
This script will update type of CODE field from INTEGER type, LENGTH = 5 to CHAR type, LENGTH=6;
ALTER TABLE IDENTITY
       ALTER COLUMN CODE CHAR(6) ;

No comments