Database Management System Lecture - 27 © Virtual University of Pakistan
© Virtual University of Pakistan Alter Table Statement Purpose is to make changes in the definition of a table already created through Create statement Can add, drop attributes or constraints, activate or deactivate constraints; the format is © Virtual University of Pakistan
© Virtual University of Pakistan ALTER TABLE table { [ ALTER COLUMN column_name { new_data_type [ ( precision [ , scale ] ) ] [ NULL | NOT NULL ] ] | ADD { [ < column_definition > ] | column_name AS computed_column_expression } [ ,...n ] | DROP { [ CONSTRAINT ] constraint_name | COLUMN column } [ ,...n ] | { CHECK | NOCHECK } CONSTRAINT { ALL | constraint_name [ ,...n ] } } © Virtual University of Pakistan
© Virtual University of Pakistan Alter Table Command ALTER TABLE Student add constraint fk_st_pr foreign key (prName) references Program (prName) ALTER TABLE program add constraint ck_totSem check (totSem < 9) © Virtual University of Pakistan
Removing or Changing Attribute ALTER TABLE student ALTER COLUMN stFName char(20) Alter table student drop column curSem drop constraint ck_st_pr © Virtual University of Pakistan
Removing Rows and Tables TRUNCATE TABLE table_name Truncate table class Delete can also be used DROP TABLE table_name © Virtual University of Pakistan
Data Manipulation Language Insert Select Update © Virtual University of Pakistan
© Virtual University of Pakistan Insert Statement To insert records into tables INSERT [ INTO] table { [ ( column_list ) ] { VALUES ( { DEFAULT | NULL | expression } [ ,...n] ) } } | DEFAULT VALUES © Virtual University of Pakistan
Database Management System Lecture - 27 © Virtual University of Pakistan