ALTER TABLE/ORDER BY CLAUSE
ALTERcommand on table. The ALTER command is used to change the structure of the table. For ex Adding a column, Deleting a column, Or Changing the Data Type of the column etc.
- Changing data type of column.
ALTER TABLE Winform_1
ALTER column Age varchar(10)
ALTER column Age varchar(10)
- Adding column to table.
ALTER TABLE WinForm_1
ADD address varchar(20)
ADD address varchar(20)
addressis added.
- Dropping a column.
ALTER table WinForm_1
DROP column address
DROP column address
order byclause. The
order byis used to select data from database in particular order or particular column.
SELECT column_name1,column_name2 from table_name
ORDER BY column_name ASC|DESC
ORDER BY column_name ASC|DESC
ID | Name | City |
State |
---|---|---|---|
1 | Raj | Mumbai |
Maharashtra |
2 | Rahul | Nashik |
Maharashtra |
3 | Saurabh | Nagar | Maharashtra |
4 | Ryan | panaji | Goa |
SELECT * from Detail ORDER BY ID desc
ID | Name |
City | State |
---|---|---|---|
4 | Ryan | panaji | Goa |
3 | Saurabh | Nagar | Maharashtra |
2 | Rahul | Nashik | Maharashtra |
1 | Raj | Mumbai | Maharashtra |
For example, Consider the following table.
ID | Name |
State |
---|---|---|
1 | Anoop |
Delhi |
2 | Ankit Pandey |
Pune |
3 4 |
Gaurav Kapoor Arjit Singh |
Delhi Punjab |
SELECT *
FROM [dbo].[tbl_Record] order by Name,State
Output
ID | Name |
State |
---|---|---|
1 | Anoop |
Delhi |
2 | Ankit Pandey |
Pune |
3 4 |
Gaurav Kapoor Arjit Singh |
Delhi Punjab |
ALTER TABLE/ORDER BY CLAUSE
Reviewed by LanguageExpert
on
August 21, 2017
Rating:
No comments