Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objectives In this lesson, you will learn to:

Similar presentations


Presentation on theme: "Objectives In this lesson, you will learn to:"— Presentation transcript:

1 Objectives In this lesson, you will learn to:
Identify the features of client/server architecture Identify the input requirements for a query Plan and create a format for the query output Identify and use sources of data for a query Identify and use different types of queries Use the SELECT statement with logical operators

2 Getting Started Client/Server Architecture
In this architecture, the functionality of the application is split between two processes: the client process and the server process The client process handles the data input and the user interface issues The server process performs all validations on the data

3 Getting Started (Contd.)
Benefits of the two-tier model (Client/Server) model are: Data Sharing: Data is separated from the client side and is stored at a central location where all users have access to the data. Reduces duplication and maintenance: Since data is stored centrally, data maintenance is easy. There is no duplication of data and therefore no inconsistency in the data stored.

4 Getting Started (Contd.)
Structured Query Language SQL Server provides the Structured Query Language (SQL) to access data objects from the server MS-SQL Server has added more features to the base-level syntax of SQL and has its own SQL called Transact-SQL (T-SQL)

5 Draft the query The SELECT Statement
Enables you to access and retrieve data from a database Syntax: SELECT [ALL | DISTINCT] select_column_list [INTO [new_table_name]] [FROM {table_name | view_name} [(optimizer_hints)][[, {table_name2 | view_name2}[(optimizer_hints)] [WHERE clause] [GROUP BY clause][HAVING clause] [ORDER BY clause][COMPUTE clause] [FOR <expr>]

6 Draft the query (Contd.) Using Literals
The result set of a data query statement can be made more readable by including a string called a literal in the SELECT list Literals are enclosed in single quotes and get printed exactly as they are written in the SELECT list

7 Execute the query Action: Connect to the server
Connect to the database Method 1: Choose the database () from the SQL Query Analyzer database drop-down list Method 2: In the Query Analyzer window, type: USE DATABASE

8 Execute the query (Contd.)
In the Query Analyzer window, type the query: Execute the query Click the Execute option from the Query menu on the menu bar or Click the Execute button on the toolbar

9 Verify that the query output is as per the required results
Check whether: The required columns are displayed

10 Displaying Specific Columns With User-Friendly Column Headings

11 Task List Draft the query Execute the query
Verify that the query output is as per the required results

12 Draft the query Displaying Columns With User-Defined Headings Syntax
Method 1: SELECT column_heading=column_name[,column name…] FROM table_name Method 2: SELECT column_name column_heading [,column_name…] FROM table_name

13 Displaying Selected Rows From a Table

14 Task List Create a format for the query output Draft the query
Execute the query Verify that the query output is as per the required results

15 Draft the query The SELECT…WHERE Statement
Retrieves and displays data with a specific condition Syntax SELECT column_list FROM table_name WHERE search_condition

16 Arithmetic Operators SQL Server supports operators that perform arithmetic operations such as addition, subtraction, division, and multiplication on numeric columns The arithmetic operators supported by SQL Server are: + (for Addition) - (for Subtraction) / (for Division) * (for Multiplication) % (for Modulo)

17 Arithmetic Operators (Contd.)
Some rules regarding the use of arithmetic operators are: Arithmetic operations can be performed on numeric columns or numeric constants The Modulo (%) operator cannot be used with columns of money, smallmoney, float, or real datatypes

18 Arithmetic Operators (Contd.)
Operator Precedence When multiple arithmetic operators are used in a single query, the processing of the operation takes place according to the precedence of arithmetic operators The precedence level of arithmetic operators in an expression is multiplication (*), division (/), modulo (%) followed by subtraction (-) and addition (+) The precedence of the operators can be changed by using the primary grouping object called parentheses (())

19 Search Based on Conditions
SQL Server provides a few methods for searching rows in a table. These methods can be broadly categorized as follows: Logical operators Comparison operators Range operators List operators

20 Draft the query Logical Operator - Multiple search conditions can be combined by using the following logical operators: ORreturns the result when any of the specified search conditions is true ANDreturns the result when all the specified search conditions are true NOT neutralizes the expression that follows it When more than one logical operator is combined in the WHERE clause, the order of precedence is NOT, AND, and OR Parentheses can be used to change the logical order of precedence

21 Draft the query (Contd.)
Syntax SELECT column_list FROM table_name WHERE conditional_expression {AND/OR}[NOT] conditional_expression

22 More on Operators Apart from logical operators, SQL Server also supports the following operators: Comparison Operators Range Operators List Operators

23 More on Operators (Contd.)
Comparison Operators Comparison operators allow row retrieval from a table based on the condition specified in the WHERE clause Syntax SELECT column_list FROM table_name WHERE expression1 comparison_operator expression2

24 More on Operators (Contd.)
Range Operators The range operator is used to retrieve data that can be extracted in ranges. The range operators are: BETWEEN NOT BETWEEN Syntax SELECT column_list FROM table_name WHERE expression1 range_operator expression2 AND expression3

25 More on Operators (Contd.)
List Operators The IN operator allows the selection of values that match any one of the values in a list The NOT IN operator restricts the selection of values that match any one of the values in a list Syntax SELECT column_list FROM table_name WHERE expression list_operator (‘value_list‘)

26 Summary In this lesson, you learned that:
A database management system consists of a Server, a database (or multiple databases) with tables containing data, and a client (front-end) that helps a user interact with the server to retrieve data. The language provided by SQL Server to access data from a database is known as Structured Query Language (SQL). Microsoft SQL Server provides a customized implementation of SQL called T-SQL.

27 Summary (Contd.) SQL Server provides a SELECT statement to access and retrieve data from a database. The SELECT statement queries the server to prepare a result and return it to the client application. The SELECT statement can be used to retrieve specific column(s) from the table by specifying the column names from the table. The SELECT statement along with the asterisk (*) symbol produces the result that contains the details of all the columns in the table.

28 Summary (Contd.) The order of the columns can be changed in the result set of the SELECT statement by specifying the individual column names separated by a comma. SQL Server provides two methods for specifying the column heading. In the first method, the column heading is specified before the column name whereas in the second method, the column name is specified before the column heading. The WHERE clause is provided by SQL Server to specify the condition to retrieve specific data. The result set of the data query statement can be made more readable by including a string called literals in the SELECT list.

29 Summary (Contd.) SQL Server supports operators that perform arithmetic operations like addition, subtraction, division, and multiplication on numeric columns. In a mixed mode arithmetic operation, the lower datatype value gets converted into a higher datatype value according to datatype precedence. SQL Server provides the following set of operators: Logical operators like AND, OR and NOT Comparison operators like =, >, <, >=, <=, ! =, !< and !> Range operators like BETWEEN and NOT BETWEEN List operators like IN and NOT IN


Download ppt "Objectives In this lesson, you will learn to:"

Similar presentations


Ads by Google