We use the Select statement to read data from the database. If we want to read the specific columns in the table, we need to specify the corresponding column names as follows.
1 |
Select column1,column2 From MyTable |
If we want to read all the columns in the table, we must use * as below.
1 |
Select * From MyTable |
Usually application developers prefer to read all the columns in the table with *. But only the needed columns should be read for the application to work more efficiently.
Select TOP:
Instead of reading all of the records in the table, we can only read as much as we specify with the Select Top statement. We specify the number of records we want to read by specifying a number in the top expression.
The use of the example is as follows:
1 |
Select TOP 2 * FROM [dbo].[MyTable] |
or
1 |
Select TOP 2 column1,column2 FROM [dbo].[MyTable] |
or
1 |
Select TOP 25 Percent * FROM [dbo].[MyTable] |