1.Order by:
The sql order by is used to sort the results in ascending or descending order.
By default it will sort the results in ascending order.
Syntax: Select column_Names from table order by column_Names asc|Desc
Command:
Output:
2.Select into:
Select into command copies the data from one table and inserts the data into the new table.
Automatically new table will create.
Syntax: select * into NewTable from ExistingTable
To copy few columns in the table:
Syntax: select column_names into NewTable in from ExistingTable
Command:
4.Insert Into Select:
Command:
Output:
5.BackUp:
The main reason for data backup is to save important files.If a system crash or hard drive failures occurs Then we can restore the backup_database..
The sql order by is used to sort the results in ascending or descending order.
By default it will sort the results in ascending order.
Syntax: Select column_Names from table order by column_Names asc|Desc
Command:
Output:
2.Select into:
Select into command copies the data from one table and inserts the data into the new table.
Automatically new table will create.
Syntax: select * into NewTable from ExistingTable
To copy few columns in the table:
Syntax: select column_names into NewTable in from ExistingTable
Command:
Output:
3.Select into with condition
Command:
Output:
- It will copy the data from one table and insert into another existing table.
- It will not create new table.
- It copies the data from one existing table and insert into another existing table.
- If the values are not filled then it wil contain null values
Command:
Output:
5.BackUp:
The main reason for data backup is to save important files.If a system crash or hard drive failures occurs Then we can restore the backup_database..
- Backup is the way to protect data from Media failures,Hardware failures.
- Full Database backups represent the whole database at the time of the backup finished.
- Differential database backups contain only changes made to the database.
Step-1: Expand databases and select the database which you want to backup.Right Click on the database.
Step-2: Select the backup type in the backup option.i.e Full or Differential
Step-3: After selecting Full backup type, Click on Add button to add the Backup in another disk
Step-4: After clicking Add button one window will open , Browse the destination disk
Step-5: Select the required path for the backup file and specify the filename.Click ok button
Step-6: After clicking the ok button. A window will open to confirm your destination path.Click ok button.
Step-7: Afer Clicking ok button.Select the new path and click ok button.
Step-8: After clicking ok button a message will be displayed.
6.Case:
The Sql case command is used to create different outputs based on condition.
Command:
Output:
7.Null Function:
1)IsNull:
Command:
Here the student phone number is null.so, when we calculate null then total is 1
Output
Step-3: After selecting Full backup type, Click on Add button to add the Backup in another disk
Step-4: After clicking Add button one window will open , Browse the destination disk
Step-5: Select the required path for the backup file and specify the filename.Click ok button
Step-6: After clicking the ok button. A window will open to confirm your destination path.Click ok button.
Step-7: Afer Clicking ok button.Select the new path and click ok button.
Step-8: After clicking ok button a message will be displayed.
6.Case:
The Sql case command is used to create different outputs based on condition.
Command:
Output:
7.Null Function:
1)IsNull:
- It is used to allow you to return an alternative value when the actual value is null.
- Its scope is with in that command.
- If the Expression is not null then it will return the expression.
Command:
Here the student phone number is null.so, when we calculate null then total is 1
Output
Command:
Output
Command:Applying is null function
2)Coalesce:
- It is also like is null function But it will allow number of values.
- It will return the First non null value in a list.
Syntax: Coalesce(Expression,value_1,value_2)
Command:
Output:
8.Patindex:
- The Patindex() function returns the position of a pattern in a string.
- It is not case sensitive.
- The string position starts from 1.
- If the pattren is not found then it will return 0.
Syntax: patindex(%Pattren%,String)
- %% :It is required.Match any string
- []:Matches any character in the brackets.
- [^]:Matches any character not in the brackets.
Command:
Output:
Command:
Output:
Command:
Output:
9.Stuff:
The stuff function deletes a part of a string and inserts another string into the string strating at a specified position.
Syntax: Stuff(String, start, length, new_String)
10.Comments:
Comments are readable explanations in the queries.
The code or queries with in the comments will never execute.
we have two types of comments.
i.Single line comment: -- Code--
ii.Multi line comment: /* Code */