Professional Documents
Culture Documents
DBMS Practical File
DBMS Practical File
PRACTICAL JOURNAL
OF
DATABASE MANAGEMENT SYSTEM
CS-502
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
PRACTICAL: 1
ALTER TABLE enables you to change the structure of an existing table. For example, you can add or
delete columns, change the type of existing columns, or rename columns or the table itself.
A) TO ADD A NEW COLUMN
a) To add the column as the first column of the table.
Alter Table TableName add NewColumnName datatype FIRST
Example: Alter table Student add School varchar(30) not null default ‘’ FIRST
B) TO DELETE A COLUMN
Alter Table TableName DROP ColumnName
Example: Alter table Student DROP School
C) TO RENAME A COLUMN
Alter table <table> add Primary Key <Primary Key Name> (<field1>,<field2>..)
3. 2 Add Unique Key:
Alter table <table> add Unique Key <Unique Key Name>
3.3 Drop Primary Key:
Alter table <table> drop Primary Key <Primary Key Name>
);
{Note: For primary key and Unique Key Indices are created by default}
After Table Creation:
CREATE INDEX StationId ON Station(StationId)
3.6 Drop Index:
This command will set the first character of a varchar field in uppercase and the rest in lowercase.
Update TableName setFieldName=CONCAT(UPPER(SUBSTRING(FieldName,1,1)),
LOWER(SUBSTRING(FIELD NAME,2)));