SQL SELECT Statement
To select all the columns from a Table, so it is converted into
In Microsoft SQL Server, you follow the convention as –
Suppose your database name is AdventureWorks2017, Schema Name is Production and Table name is Product and you are already connected to the database, then you do not need to type –
because you are already connected to AdventureWorks2017 database.
So, you can simply code –
The SQL standard to terminate a query is to use a semicolon at the end of the query and some of the databases strictly require you to place a semicolon at the end of the query.
Order Of execution in SQL
Even though the SELECT statement comes first but the SQL server Engine considers the FROM clause first and then processes the SELECT clause.
So, when you code –
Microsoft SQL Server engine will process the FROM clause first and then followed by SELECT clause.
So, when you code –
It is same as –
or, it is same as –
But, I strongly suggest to use Capital letters for all the SQL keywords like SELECT, FROM, etc.
Selecting Individual column or multiple columns
If you wish to select all the records of ‘CountryRegionCode’ column from ‘CountryRegion’ table which is present under the ‘Person’ schema, then you can code the SQL Query as –
If you also wish to select all the records of ‘Name’ and ‘CountryRegionCode’ columns from ‘CountryRegion’, then you can code the SQL Query as –
Selecting column which has spaces in it
In Microsoft SQL Server, if you have a column name that contains a space, then, you have to surround that particular column name within square brackets.
For example, if you have a table with the name as ‘Customers’ under the Schema ‘Person’ and you have a column with the name as ‘First Name’
Then, you have to select the records from that particular column name as –
It is important to understand that if you code column names inside 2 single quotes, then it is called Literal SELECT. Literal select means select ‘AS IT IS’. For Example –