SlideShare una empresa de Scribd logo
1 de 50
Querying Databases

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




©NIIT                                           SQL/lesson 1/Slide 1 of 50
Querying Databases

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




©NIIT                                            SQL/lesson 1/Slide 2 of 50
Querying Databases

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.




©NIIT                                         SQL/lesson 1/Slide 3 of 50
Querying Databases

Getting Started (Contd.)
 Features of MS SQL Server
     Microsoft SQL Server provides various features to manage
      data. Some of the features offered by Microsoft SQL Server
      are:
        ® Web-Enabled

        ® Scalable   and Reliable
        ® Fastest   Time-to-Market




©NIIT                                       SQL/lesson 1/Slide 4 of 50
Querying Databases

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)
 Datatypes in SQL Server
     SQL Server can store various types of data like char,
      money, int, or datetime



©NIIT                                        SQL/lesson 1/Slide 5 of 50
Querying Databases

1.D.1 Displaying Specific Attributes From a Table
 The details regarding recruitment are stored in the
  RECRUITMENT database on the local SQL server. These
  tables contain data on candidates, their qualifications and
  contact details, the vacancies available, and other information
  required by the recruitment agency. A report containing the
  name, city, and telephone number of all the external
  candidates is required.




©NIIT                                         SQL/lesson 1/Slide 6 of 50
Querying Databases

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




©NIIT                                          SQL/lesson 1/Slide 7 of 50
Querying Databases

Create a format for the query output
 Result:
     The output required from the query is the specific details
      of all the external candidates
     The column headings required in the report are the name,
      city, and telephone number of the external candidates
     The format of the report is as follows:

          vFirstName    vLastName       cCity            cPhone




©NIIT                                           SQL/lesson 1/Slide 8 of 50
Querying Databases

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 BROWSE]
©NIIT                                       SQL/lesson 1/Slide 9 of 50
Querying Databases

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




©NIIT                                          SQL/lesson 1/Slide 10 of 50
Querying Databases

Draft the query (Contd.)
 Result:
     The information is available in the Recruitment database
     The information available in the table ExternalCandidate is
      required
     The specific attributes required from the ExternalCandidate
      table are vFirstName, vLastName, cCity, and cPhone




©NIIT                                        SQL/lesson 1/Slide 11 of 50
Querying Databases

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




©NIIT                                         SQL/lesson 1/Slide 12 of 50
Querying Databases

Execute the query (Contd.)
     In the Query Analyzer window, type:
        SELECT vFirstName, vLastName, cCity,
        cPhone
        FROM ExternalCandidate
     Execute the query
        ® Click
              the Execute option from the Query menu on the
          menu bar
          or
        ® Click   the Execute button on the toolbar

©NIIT                                           SQL/lesson 1/Slide 13 of 50
Querying Databases

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




©NIIT                                      SQL/lesson 1/Slide 14 of 50
Querying Databases

Just a Minute…
 In Tebisco, there is a review by senior management on
  manpower. You need to write a query to display a list of the
  budgeted and the actual people available for various roles
  from the Recruitment database.




©NIIT                                       SQL/lesson 1/Slide 15 of 50
Querying Databases

1.D.2 Displaying Specific Columns With User-Friendly
Column Headings
 The percentage charge of contract recruiters for hiring
  candidates is under review. The names of the contract
  recruiters and their hire charges are required. The report
  should contain user-friendly column headings as specified
  in the following format:

                Recruiter Name     Hire Charge




©NIIT                                        SQL/lesson 1/Slide 16 of 50
Querying Databases

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




©NIIT                                         SQL/lesson 1/Slide 17 of 50
Querying Databases

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




©NIIT                                   SQL/lesson 1/Slide 18 of 50
Querying Databases

Draft the query (Contd.)
 Result:
     The information is available in the table ContractRecruiter
     The columns required are cName, siPercentageCharge with the
      column headings 'Recruiter Name' and 'Hire Charge' from the
      table




©NIIT                                            SQL/lesson 1/Slide 19 of 50
Querying Databases

Execute the query
 Action:
     In the Query Analyzer window, type:
        SELECT 'Recruiter Name' = cName, 'Hire
        Charge' = siPercentageCharge
        FROM ContractRecruiter
     Execute the query




©NIIT                                       SQL/lesson 1/Slide 20 of 50
Querying Databases

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




©NIIT                                      SQL/lesson 1/Slide 21 of 50
Querying Databases

1.D.3 Displaying Selected Rows From a Table
 Campus recruitment by Tebisco needs to be conducted in
  the state of California. Therefore, details of all colleges in
  the state of California are required.




©NIIT                                          SQL/lesson 1/Slide 22 of 50
Querying Databases

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




©NIIT                                         SQL/lesson 1/Slide 23 of 50
Querying Databases

Create a format for the query output
 Result:
     The output required is the details of all colleges in the
      state of California
     The format of the report is shown below:


    cCollegeCode   cCollegeName   vCollegeAddress   cCity     cState    cZip   cPhone




©NIIT                                                       SQL/lesson 1/Slide 24 of 50
Querying Databases

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




©NIIT                                        SQL/lesson 1/Slide 25 of 50
Querying Databases

Draft the query (Contd.)
     Result:
        ® The   information is available in the College table
        ® The column headings are the attribute names of the
         College table
        ® Thecondition is that the state is ‘California’, that is,
         cState=‘California‘
        ® Therefore,   the query using the SELECT statement
         should be:
         SELECT * FROM College
         WHERE cState = 'California'
©NIIT                                            SQL/lesson 1/Slide 26 of 50
Querying Databases

Execute the query
 Action:
     In the Query Analyzer window, type the query.
     Execute the query




©NIIT                                      SQL/lesson 1/Slide 27 of 50
Querying Databases

Verify that the query output is as per the required
results
 Check whether:
     All columns are displayed
     Only rows in which the value of the cState attribute is
      California are displayed




©NIIT                                         SQL/lesson 1/Slide 28 of 50
Querying Databases

Just a Minute…
 The hiring charges of contract recruiters (charging more than
   8 percent of the annual salary as their percentage) are
   under review. The names, addresses, and the hiring
   charges of these contract recruiters are required. Write a
   query to display the required information.




©NIIT                                       SQL/lesson 1/Slide 29 of 50
Querying Databases

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)

©NIIT                                       SQL/lesson 1/Slide 30 of 50
Querying Databases

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




©NIIT                                       SQL/lesson 1/Slide 31 of 50
Querying Databases

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 (())



©NIIT                                          SQL/lesson 1/Slide 32 of 50
Querying Databases

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




©NIIT                                      SQL/lesson 1/Slide 33 of 50
Querying Databases

1.D.4. Displaying Rows That Satisfy Multiple Conditions
 Candidates who have scored marks between 80 and 100 in a
  test need to be called for an interview. Therefore, a report
  displaying the names of candidates and their scores is
  required




©NIIT                                      SQL/lesson 1/Slide 34 of 50
Querying Databases

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




©NIIT                                         SQL/lesson 1/Slide 35 of 50
Querying Databases

Create a format for the query output
 Result:
     The output requirements for the report are the names and
      the test scores of only those candidates who have scored
      marks between 80 and 100 in a test
     The format of the report is shown below:

            vFirstName      vLastName       siTestScore




©NIIT                                       SQL/lesson 1/Slide 36 of 50
Querying Databases

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

©NIIT                                       SQL/lesson 1/Slide 37 of 50
Querying Databases

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




©NIIT                               SQL/lesson 1/Slide 38 of 50
Querying Databases

Draft the query (Contd.)
 Result:
     The required information is available in the
      ExternalCandidate table
     The column headings are the attribute names of the
      relevant columns in the ExternalCandidate table
     The condition to be satisfied is that the test score should be
      greater than or equal to 80 (siTestScore = 80) and less
      than or equal to 100 (siTestScore = 100)
     Therefore, the query using the SELECT statement should
      be:
        SELECT vFirstName, vLastName, siTestScore
        FROM ExternalCandidate
        WHERE siTestScore = 80 AND siTestScore =
©NIIT   100                          SQL/lesson 1/Slide 39 of 50
Querying Databases

Execute the query
 Action:
     In the Query Analyzer window, type the query
     Execute the query




©NIIT                                      SQL/lesson 1/Slide 40 of 50
Querying Databases

Verify that the query output is as per the required
results
 Check whether:
     The required columns are displayed
     All the rows displayed have values of siTestScore
      between 80 and 100




©NIIT                                       SQL/lesson 1/Slide 41 of 50
Querying Databases

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




©NIIT                                      SQL/lesson 1/Slide 42 of 50
Querying Databases

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




©NIIT                                      SQL/lesson 1/Slide 43 of 50
Querying Databases

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


©NIIT                                        SQL/lesson 1/Slide 44 of 50
Querying Databases

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‘)




©NIIT                                        SQL/lesson 1/Slide 45 of 50
Querying Databases

Just a Minute…
 In order to identify the successful candidates, who took the
  test between March 5, 2001 and March 12, 2001, a report
  displaying the names of candidates and their scores needs
  to be created. The format of the report is as follows:


        vFirstName   vLastName     siTestScore     dTestDate




©NIIT                                        SQL/lesson 1/Slide 46 of 50
Querying Databases

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.



©NIIT                                       SQL/lesson 1/Slide 47 of 50
Querying Databases

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.



©NIIT                                        SQL/lesson 1/Slide 48 of 50
Querying Databases

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.

©NIIT                                         SQL/lesson 1/Slide 49 of 50
Querying Databases

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

©NIIT                                         SQL/lesson 1/Slide 50 of 50

Más contenido relacionado

La actualidad más candente

CIS 336 Final Exam 2 (Devry)
CIS 336 Final Exam 2 (Devry) CIS 336 Final Exam 2 (Devry)
CIS 336 Final Exam 2 (Devry) critter03
 
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAINFP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAINSyahriha Ruslan
 
FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMAmira Dolce Farhana
 
Developing Microsoft SQL Server 2012 Databases 70-464 Pass Guarantee
Developing Microsoft SQL Server 2012 Databases 70-464 Pass GuaranteeDeveloping Microsoft SQL Server 2012 Databases 70-464 Pass Guarantee
Developing Microsoft SQL Server 2012 Databases 70-464 Pass GuaranteeSusanMorant
 
CIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.comCIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.comkopiko105
 
CIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.comCIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.comwilliamwordsworth11
 
CIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.comCIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.comagathachristie171
 
CIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.comCIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.comagathachristie208
 
CIS 336 STUDY Education Begins--cis336study.com
CIS 336 STUDY Education Begins--cis336study.comCIS 336 STUDY Education Begins--cis336study.com
CIS 336 STUDY Education Begins--cis336study.comagathachristie235
 
CIS 336 PAPERS Lessons in Excellence--cis336papers.com
CIS 336 PAPERS Lessons in Excellence--cis336papers.comCIS 336 PAPERS Lessons in Excellence--cis336papers.com
CIS 336 PAPERS Lessons in Excellence--cis336papers.comthomashard82
 
CIS 336 Life of the Mind/newtonhelp.com   
CIS 336 Life of the Mind/newtonhelp.com   CIS 336 Life of the Mind/newtonhelp.com   
CIS 336 Life of the Mind/newtonhelp.com   bellflower3
 

La actualidad más candente (20)

CIS 336 Final Exam 2 (Devry)
CIS 336 Final Exam 2 (Devry) CIS 336 Final Exam 2 (Devry)
CIS 336 Final Exam 2 (Devry)
 
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAINFP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
 
FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEM
 
Developing Microsoft SQL Server 2012 Databases 70-464 Pass Guarantee
Developing Microsoft SQL Server 2012 Databases 70-464 Pass GuaranteeDeveloping Microsoft SQL Server 2012 Databases 70-464 Pass Guarantee
Developing Microsoft SQL Server 2012 Databases 70-464 Pass Guarantee
 
CIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.comCIS 336 Inspiring Innovation -- cis336.com
CIS 336 Inspiring Innovation -- cis336.com
 
CIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.comCIS336 Education for Service--cis336.com
CIS336 Education for Service--cis336.com
 
CIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.comCIS 336 Achievement Education --cis336.com
CIS 336 Achievement Education --cis336.com
 
CIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.comCIS 336 Redefined Education--cis336.com
CIS 336 Redefined Education--cis336.com
 
CIS 336 STUDY Education Begins--cis336study.com
CIS 336 STUDY Education Begins--cis336study.comCIS 336 STUDY Education Begins--cis336study.com
CIS 336 STUDY Education Begins--cis336study.com
 
Assignment#01
Assignment#01Assignment#01
Assignment#01
 
CIS 336 PAPERS Lessons in Excellence--cis336papers.com
CIS 336 PAPERS Lessons in Excellence--cis336papers.comCIS 336 PAPERS Lessons in Excellence--cis336papers.com
CIS 336 PAPERS Lessons in Excellence--cis336papers.com
 
Assignment#02
Assignment#02Assignment#02
Assignment#02
 
CIS 336 Life of the Mind/newtonhelp.com   
CIS 336 Life of the Mind/newtonhelp.com   CIS 336 Life of the Mind/newtonhelp.com   
CIS 336 Life of the Mind/newtonhelp.com   
 
Assignment#08
Assignment#08Assignment#08
Assignment#08
 
Assignment#04
Assignment#04Assignment#04
Assignment#04
 
Lab
LabLab
Lab
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
1 z0 047
1 z0 0471 z0 047
1 z0 047
 
Assignment#05
Assignment#05Assignment#05
Assignment#05
 
Assignment#06
Assignment#06Assignment#06
Assignment#06
 

Destacado

Comp tia n+_session_06
Comp tia n+_session_06Comp tia n+_session_06
Comp tia n+_session_06Niit Care
 
02 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_0202 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_02Niit Care
 
02 t1 s2_linux_lesson2
02 t1 s2_linux_lesson202 t1 s2_linux_lesson2
02 t1 s2_linux_lesson2Niit Care
 
Comp tia n+_session_08
Comp tia n+_session_08Comp tia n+_session_08
Comp tia n+_session_08Niit Care
 
01 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_0101 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_01Niit Care
 
Comp tia n+_session_11
Comp tia n+_session_11Comp tia n+_session_11
Comp tia n+_session_11Niit Care
 
NIIT Presentation 1
NIIT Presentation 1NIIT Presentation 1
NIIT Presentation 1NIIT Bahrain
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 
Step by Step Installation of Microsoft SQL Server 2012
Step by Step Installation of Microsoft SQL Server 2012 Step by Step Installation of Microsoft SQL Server 2012
Step by Step Installation of Microsoft SQL Server 2012 Sameh AboulDahab
 

Destacado (15)

Comp tia n+_session_06
Comp tia n+_session_06Comp tia n+_session_06
Comp tia n+_session_06
 
Niit
NiitNiit
Niit
 
02 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_0202 iec t1_s1_plt_session_02
02 iec t1_s1_plt_session_02
 
02 t1 s2_linux_lesson2
02 t1 s2_linux_lesson202 t1 s2_linux_lesson2
02 t1 s2_linux_lesson2
 
Dacj 1-3 b
Dacj 1-3 bDacj 1-3 b
Dacj 1-3 b
 
Comp tia n+_session_08
Comp tia n+_session_08Comp tia n+_session_08
Comp tia n+_session_08
 
01 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_0101 iec t1_s1_plt_session_01
01 iec t1_s1_plt_session_01
 
Comp tia n+_session_11
Comp tia n+_session_11Comp tia n+_session_11
Comp tia n+_session_11
 
SQL | Computer Science
SQL | Computer ScienceSQL | Computer Science
SQL | Computer Science
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
NIIT Presentation 1
NIIT Presentation 1NIIT Presentation 1
NIIT Presentation 1
 
Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 
Step by Step Installation of Microsoft SQL Server 2012
Step by Step Installation of Microsoft SQL Server 2012 Step by Step Installation of Microsoft SQL Server 2012
Step by Step Installation of Microsoft SQL Server 2012
 

Similar a Sql xp 01

Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizerterraborealis
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxchristinemaritza
 
Basics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration TechniquesBasics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration TechniquesValmik Potbhare
 
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesC# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesSami Mut
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005Govind Raj
 
Structured Query Language for Data Management 2 Sructu.docx
Structured Query Language for Data Management      2 Sructu.docxStructured Query Language for Data Management      2 Sructu.docx
Structured Query Language for Data Management 2 Sructu.docxjohniemcm5zt
 
CC105-WEEK10-11-INTRODUCTION-TO-SQL.pdf
CC105-WEEK10-11-INTRODUCTION-TO-SQL.pdfCC105-WEEK10-11-INTRODUCTION-TO-SQL.pdf
CC105-WEEK10-11-INTRODUCTION-TO-SQL.pdfozaixyzo
 
Introduction to the Structured Query Language SQL
Introduction to the Structured Query Language SQLIntroduction to the Structured Query Language SQL
Introduction to the Structured Query Language SQLHarmony Kwawu
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesKeshav Murthy
 
Access tips access and sql part 1 setting the sql scene
Access tips  access and sql part 1  setting the sql sceneAccess tips  access and sql part 1  setting the sql scene
Access tips access and sql part 1 setting the sql scenequest2900
 
Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库renguzi
 

Similar a Sql xp 01 (20)

Sql xp 08
Sql xp 08Sql xp 08
Sql xp 08
 
Sql xp 03
Sql xp 03Sql xp 03
Sql xp 03
 
Sql xp 05
Sql xp 05Sql xp 05
Sql xp 05
 
Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizer
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
 
Basics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration TechniquesBasics of Microsoft Business Intelligence and Data Integration Techniques
Basics of Microsoft Business Intelligence and Data Integration Techniques
 
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesC# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
 
01 basic orders
01   basic orders01   basic orders
01 basic orders
 
Sq lite module6
Sq lite module6Sq lite module6
Sq lite module6
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005
 
Structured Query Language for Data Management 2 Sructu.docx
Structured Query Language for Data Management      2 Sructu.docxStructured Query Language for Data Management      2 Sructu.docx
Structured Query Language for Data Management 2 Sructu.docx
 
CC105-WEEK10-11-INTRODUCTION-TO-SQL.pdf
CC105-WEEK10-11-INTRODUCTION-TO-SQL.pdfCC105-WEEK10-11-INTRODUCTION-TO-SQL.pdf
CC105-WEEK10-11-INTRODUCTION-TO-SQL.pdf
 
F04302053057
F04302053057F04302053057
F04302053057
 
ch4
ch4ch4
ch4
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Introduction to the Structured Query Language SQL
Introduction to the Structured Query Language SQLIntroduction to the Structured Query Language SQL
Introduction to the Structured Query Language SQL
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql Features
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Access tips access and sql part 1 setting the sql scene
Access tips  access and sql part 1  setting the sql sceneAccess tips  access and sql part 1  setting the sql scene
Access tips access and sql part 1 setting the sql scene
 
Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库
 

Más de Niit Care (20)

Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Dacj 1-3 a
Dacj 1-3 aDacj 1-3 a
Dacj 1-3 a
 

Último

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Sql xp 01

  • 1. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 1 of 50
  • 2. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 2 of 50
  • 3. Querying Databases 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. ©NIIT SQL/lesson 1/Slide 3 of 50
  • 4. Querying Databases Getting Started (Contd.) Features of MS SQL Server Microsoft SQL Server provides various features to manage data. Some of the features offered by Microsoft SQL Server are: ® Web-Enabled ® Scalable and Reliable ® Fastest Time-to-Market ©NIIT SQL/lesson 1/Slide 4 of 50
  • 5. Querying Databases 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) Datatypes in SQL Server SQL Server can store various types of data like char, money, int, or datetime ©NIIT SQL/lesson 1/Slide 5 of 50
  • 6. Querying Databases 1.D.1 Displaying Specific Attributes From a Table The details regarding recruitment are stored in the RECRUITMENT database on the local SQL server. These tables contain data on candidates, their qualifications and contact details, the vacancies available, and other information required by the recruitment agency. A report containing the name, city, and telephone number of all the external candidates is required. ©NIIT SQL/lesson 1/Slide 6 of 50
  • 7. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 7 of 50
  • 8. Querying Databases Create a format for the query output Result: The output required from the query is the specific details of all the external candidates The column headings required in the report are the name, city, and telephone number of the external candidates The format of the report is as follows: vFirstName vLastName cCity cPhone ©NIIT SQL/lesson 1/Slide 8 of 50
  • 9. Querying Databases 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 BROWSE] ©NIIT SQL/lesson 1/Slide 9 of 50
  • 10. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 10 of 50
  • 11. Querying Databases Draft the query (Contd.) Result: The information is available in the Recruitment database The information available in the table ExternalCandidate is required The specific attributes required from the ExternalCandidate table are vFirstName, vLastName, cCity, and cPhone ©NIIT SQL/lesson 1/Slide 11 of 50
  • 12. Querying Databases Execute the query Action: Connect to the server Connect to the database ® Method 1: Choose the database (RECRUITMENT) from the SQL Query Analyzer database drop-down list ® Method 2: In the Query Analyzer window, type: USE RECRUITMENT ©NIIT SQL/lesson 1/Slide 12 of 50
  • 13. Querying Databases Execute the query (Contd.) In the Query Analyzer window, type: SELECT vFirstName, vLastName, cCity, cPhone FROM ExternalCandidate Execute the query ® Click the Execute option from the Query menu on the menu bar or ® Click the Execute button on the toolbar ©NIIT SQL/lesson 1/Slide 13 of 50
  • 14. Querying Databases Verify that the query output is as per the required results Check whether: The required columns are displayed ©NIIT SQL/lesson 1/Slide 14 of 50
  • 15. Querying Databases Just a Minute… In Tebisco, there is a review by senior management on manpower. You need to write a query to display a list of the budgeted and the actual people available for various roles from the Recruitment database. ©NIIT SQL/lesson 1/Slide 15 of 50
  • 16. Querying Databases 1.D.2 Displaying Specific Columns With User-Friendly Column Headings The percentage charge of contract recruiters for hiring candidates is under review. The names of the contract recruiters and their hire charges are required. The report should contain user-friendly column headings as specified in the following format: Recruiter Name Hire Charge ©NIIT SQL/lesson 1/Slide 16 of 50
  • 17. Querying Databases Task List Draft the query Execute the query Verify that the query output is as per the required results ©NIIT SQL/lesson 1/Slide 17 of 50
  • 18. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 18 of 50
  • 19. Querying Databases Draft the query (Contd.) Result: The information is available in the table ContractRecruiter The columns required are cName, siPercentageCharge with the column headings 'Recruiter Name' and 'Hire Charge' from the table ©NIIT SQL/lesson 1/Slide 19 of 50
  • 20. Querying Databases Execute the query Action: In the Query Analyzer window, type: SELECT 'Recruiter Name' = cName, 'Hire Charge' = siPercentageCharge FROM ContractRecruiter Execute the query ©NIIT SQL/lesson 1/Slide 20 of 50
  • 21. Querying Databases Verify that the query output is as per the required results Check whether: The required columns are displayed The required column headings are displayed ©NIIT SQL/lesson 1/Slide 21 of 50
  • 22. Querying Databases 1.D.3 Displaying Selected Rows From a Table Campus recruitment by Tebisco needs to be conducted in the state of California. Therefore, details of all colleges in the state of California are required. ©NIIT SQL/lesson 1/Slide 22 of 50
  • 23. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 23 of 50
  • 24. Querying Databases Create a format for the query output Result: The output required is the details of all colleges in the state of California The format of the report is shown below: cCollegeCode cCollegeName vCollegeAddress cCity cState cZip cPhone ©NIIT SQL/lesson 1/Slide 24 of 50
  • 25. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 25 of 50
  • 26. Querying Databases Draft the query (Contd.) Result: ® The information is available in the College table ® The column headings are the attribute names of the College table ® Thecondition is that the state is ‘California’, that is, cState=‘California‘ ® Therefore, the query using the SELECT statement should be: SELECT * FROM College WHERE cState = 'California' ©NIIT SQL/lesson 1/Slide 26 of 50
  • 27. Querying Databases Execute the query Action: In the Query Analyzer window, type the query. Execute the query ©NIIT SQL/lesson 1/Slide 27 of 50
  • 28. Querying Databases Verify that the query output is as per the required results Check whether: All columns are displayed Only rows in which the value of the cState attribute is California are displayed ©NIIT SQL/lesson 1/Slide 28 of 50
  • 29. Querying Databases Just a Minute… The hiring charges of contract recruiters (charging more than 8 percent of the annual salary as their percentage) are under review. The names, addresses, and the hiring charges of these contract recruiters are required. Write a query to display the required information. ©NIIT SQL/lesson 1/Slide 29 of 50
  • 30. Querying Databases 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) ©NIIT SQL/lesson 1/Slide 30 of 50
  • 31. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 31 of 50
  • 32. Querying Databases 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 (()) ©NIIT SQL/lesson 1/Slide 32 of 50
  • 33. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 33 of 50
  • 34. Querying Databases 1.D.4. Displaying Rows That Satisfy Multiple Conditions Candidates who have scored marks between 80 and 100 in a test need to be called for an interview. Therefore, a report displaying the names of candidates and their scores is required ©NIIT SQL/lesson 1/Slide 34 of 50
  • 35. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 35 of 50
  • 36. Querying Databases Create a format for the query output Result: The output requirements for the report are the names and the test scores of only those candidates who have scored marks between 80 and 100 in a test The format of the report is shown below: vFirstName vLastName siTestScore ©NIIT SQL/lesson 1/Slide 36 of 50
  • 37. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 37 of 50
  • 38. Querying Databases Draft the query (Contd.) Syntax SELECT column_list FROM table_name WHERE conditional_expression{AND/OR}[NOT] conditional_expression ©NIIT SQL/lesson 1/Slide 38 of 50
  • 39. Querying Databases Draft the query (Contd.) Result: The required information is available in the ExternalCandidate table The column headings are the attribute names of the relevant columns in the ExternalCandidate table The condition to be satisfied is that the test score should be greater than or equal to 80 (siTestScore = 80) and less than or equal to 100 (siTestScore = 100) Therefore, the query using the SELECT statement should be: SELECT vFirstName, vLastName, siTestScore FROM ExternalCandidate WHERE siTestScore = 80 AND siTestScore = ©NIIT 100 SQL/lesson 1/Slide 39 of 50
  • 40. Querying Databases Execute the query Action: In the Query Analyzer window, type the query Execute the query ©NIIT SQL/lesson 1/Slide 40 of 50
  • 41. Querying Databases Verify that the query output is as per the required results Check whether: The required columns are displayed All the rows displayed have values of siTestScore between 80 and 100 ©NIIT SQL/lesson 1/Slide 41 of 50
  • 42. Querying Databases More on Operators Apart from logical operators, SQL Server also supports the following operators: Comparison Operators Range Operators List Operators ©NIIT SQL/lesson 1/Slide 42 of 50
  • 43. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 43 of 50
  • 44. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 44 of 50
  • 45. Querying Databases 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‘) ©NIIT SQL/lesson 1/Slide 45 of 50
  • 46. Querying Databases Just a Minute… In order to identify the successful candidates, who took the test between March 5, 2001 and March 12, 2001, a report displaying the names of candidates and their scores needs to be created. The format of the report is as follows: vFirstName vLastName siTestScore dTestDate ©NIIT SQL/lesson 1/Slide 46 of 50
  • 47. Querying Databases 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. ©NIIT SQL/lesson 1/Slide 47 of 50
  • 48. Querying Databases 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. ©NIIT SQL/lesson 1/Slide 48 of 50
  • 49. Querying Databases 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. ©NIIT SQL/lesson 1/Slide 49 of 50
  • 50. Querying Databases 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 ©NIIT SQL/lesson 1/Slide 50 of 50