0% found this document useful (0 votes)
40 views3 pages

3 - ALTER - Part 3

Uploaded by

Porkodi M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

3 - ALTER - Part 3

Uploaded by

Porkodi M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Class : XII Subject: Information technology

Chapter: SQL Queries – Part 3 Worksheet: 3


Notes:

ALTER TABLE COMMAND: This command is used to modify the base table definition. The
modifications that can be done using this command are:
(a) Adding a column:
Syntax: ALTER TABLE Tablename ADD Col_name datatype;
Suppose we want to add a column ‘Age’ in the Teacher table. Following command is used
ALTER TABLE Teacher ADD Age INTEGER;
(b) Dropping a column: A column can be removed using DROP clause.
Syntax: ALTER TABLE Table_name DROP Col_name;
(c) To remove the Dept_No column in the Teacher Table
ALTER TABLE Teacher DROP Dept_no;
Altering a Column: A column definition can also be altered.
(a) Syntax: Change the datatype of a column
ALTER TABLE table_name
MODIFY col_name datatype;
To change the Datatype of Dept_no of teacher table from char to int(3).
ALTER TABLE teacher
MODIFY Dept_no INT(3);
(b) Syntax: Rename the column
ALTER TABLE table_name
CHANGE old_columnname new_columnname datatype;
To rename the column Dept_no as D_id
ALTER TABLE table_name
CHANGE Dept_no D_id char(3);

FUNCTIONS:
 Functions in SQL Server are the database object that contains a set of SQL statements to
perform a specific task.
 Single Row functions - Single row functions are the one who work on single row and return
one output per row.
Work sheet:
Consider the following table SPORTS and write SQL statements for the following:

(a) To add a column COACH_ID to the table SPORTS.


(b) To change the data type of the column SCode to integer in the table
(c) To drop the column Noofplayers from the table Sports.
(d) To rename the column SCode to Sport_code.
(e) Write the output of the following queries:

1. SELECT UCASE(Coachname) FROM SPORTS WHERE SportName=”Cricket”;


2. SELECT length(Coachname) FROM Sports;
3. select mod(29,4);
4. select POW(MONTH(“2022/3/12”),4);
5. select round(1578.256,1) from dual;
6. SELECT NOW();
7. SELECT DATE("2017-06-15");
8. SELECT DAY('2017/08/13 09:08');
9. SELECT YEAR('2017/08/25');
10. SELECT MONTH("2017-06-15");

You might also like