In T-SQL use the SELECT statement for data query, select syntax structure:
<SELECTStatement>::= [With <common_table_expression> [,... n]] <Query_expression> [ORDER by {order_by_expression | column_position [ASC | DESC] } [,... N] ] [<for clause>] [OPTION (<query_hint> [,... n] ) ] <Query_expression>::= { <Query_specification> |(<Query_expression> ) } [{UNION [ all] | EXCEPT | INTERSECT } <Query_specification> |(<Query_expression>)[. .. n] ] <Query_specification>::= SELECT [All | DISTINCT] [TOP (expression) [PERCENT] [With TIES] ] <Select_list> [Into new_table] [From {<table_source>} [,... n] ] [WHERE <search_condition>] [<group by>] [Having < search_condition >]
1. Basic SELECT query
SELECT * from [dbo]. [Product]
When you use the asterisk (*) wildcard character, all columns are returned, and the columns are displayed in the order in which they were defined.
2. Specify fields in the query record
When you don't need all of the field values in a datasheet, you can specify the name of the field you want to query, which not only shows the results clearer, but also improves the efficiency of the query.
SELECT [ProductID],[ProductName]from[dbo ]. [Product]
3. Using an expression in query results
select [ , [ productname " , [ unitprice ] * 2 as Doubleunitprice from [ dbo ". [ ]
The AS keyword indicates that the expression specifies a field name for display, where as is an optional parameter, or it can not be used.
4. Display partial Query Results
When a data table contains a large amount of data, you can limit the number of rows returned in the result set by specifying the number of records to display.
SELECT TOP [n | PERCENT] from table_name
There are two optional arguments behind top, n means that the specified n rows are returned from the query result set, and percent represents the number of rows returned from the result set for the specified percentage.
select top (10 ) * from [ dbo ". [ ]
SELECT TOP (PERCENT*from[dbo]. [Product]
SQL Server Series: SELECT Basic statement