Write SQL Server Command with Syntax

 SQL Commands: Main Tips

To interact with SQL databases, we need to know the SQL commands. We also called SQL statements.

SQL is not case-sensitive, but writing SQL commands in ALL CAPS improves readability of your code.

 

SQL Statement Syntax Examples,


SELECT Statement

SELECT * FROM Users

The asterisk (*) sign defines all columns of the table. The SELECT statement returns all columns of the Student Users. If you want Name, Age only the try below query

 

SELECT Name, Age FROM Users

 

Filtering the Data: WHERE Clause

SELECT * FROM Users WHERE Age >=18

 

LIKE operator is a logical operator that provides to apply a special filtering pattern to WHERE condition in SQL queries.

SELECT * FROM Users WHERE Name LIKE 'AN%'

 

IN operator enables us to apply multiple value filters to WHERE clause.

SELECT * FROM Users WHERE Name IN ('Anil','Aradhya')

 

The BETWEEN operator filters the data that falls into the defined begin and end value.

SELECT * FROM Users WHERE Age BETWEEN 18 AND 22

 

Sorting the Data: ORDER BY Statement

The ORDER BY keyword is used to sort the result set in ascending or descending order. The ORDER BY keyword sorts the records in ascending order by default.


To sort the records in descending order, use the DESC keyword.

To sort the records in ascending order, use the ASE keyword.


SELECT * FROM Users ORDER BY Age DESC

SELECT * FROM Users ORDER BY Age ASC

 

Eliminating the Duplicate Data: DISTINCT Clause

The SELECT DISTINCT statement is used to return only distinct values.

Inside a table Users, column Name can contains many duplicate Name (like Anil, Anil) and sometimes you only want to list the distinct values.

 SELECT DISTINCT Name FROM Users


Stored Procedure Functions View – Virtual Table
Trigger Index - Clustered, Non-clustered Cursor
Joins Error Handling - TRY CATCH @@ERROR
RAISERROR @@ROWCOUNT @@IDENTITY
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^