Docsity

SQL Data Manipulation: Reserved & User-defined Words, Writing Commands, Retrieving Data, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download SQL Data Manipulation: Reserved & User-defined Words, Writing Commands, Retrieving Data and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

SQL: Data Manipulation

Docsity.com

Introduction

  • Structured Query Language (SQL)
  • Writing an SQL Command
  • Retrieving Data
  • Building SQL Statements
  • Performing Database Updates

Docsity.com

What is SQL?

  • ISO SQL has two major components:
    • Data Definition Language (DDL)
    • Data Manipulation Language (DML)

Source: Database Systems Connolly/Begg Docsity.com

Data Definition Language (DDL)

  • Defining the database structure
    • Tables
  • Controlling access to the data
    • What a user can legally access

Source: Database Systems Connolly/Begg Docsity.com

Writing SQL Commands

  • SQL statement consists of reserved words and user-defined words - Reserved words are a fixed part of the SQL language and have a fixed meaning - User-defined words are made up by the user (according to syntax rules)

Source: Database Systems Connolly/Begg Docsity.com

Reserved Words

  • Are fixed part of the SQL language
  • Have a fixed meaning
  • Require exact spelling
  • Kept on the same line

Source: Database Systems Connolly/Begg Docsity.com

Data Manipulation

  • Select : query data in the database
  • Insert : insert data into a table
  • Update : updates data in a table
  • Delete : delete data from a table

Source: Database Systems Connolly/Begg Docsity.com

Literals

  • Non-numeric data values must be enclosed in single quotes: - โ€™16 Holland Driveโ€™ - โ€˜CS157Bโ€™
  • Numeric data values must NOT be enclosed in single quotes: - 6 - 600.

Source: Database Systems Connolly/Begg Docsity.com

Simple Query

  • Select specifies which columns are to appear in the output.
  • From specifies the table(s) to be used.
  • Where filters the rows subject to some condition(s).

Source: Database Systems Connolly/Begg Docsity.com

Simple Query

  • Group By forms groups of rows with the same column value.
  • Having filters the groups subject to some condition.
  • Order By specifies the order of the output.

Source: Database Systems Connolly/Begg Docsity.com

Use of Distinct

SELECT DISTINCT columnName

FROM tableName;

columnName A B C D

columnName A A B B C D

Docsity.com

Calculated fields

SELECT columnName/

FROM tableName

price

price

Docsity.com

Comparison Search Condition

  • An expression is evaluated left to right.
  • Subexpressions in brackets are evaluated first.
  • NOT s are evaluated before AND s and OR s.
  • AND s are evaluated before OR s.

Source: Database Systems Connolly/Begg Docsity.com

Range Search Condition

SELECT columnName FROM tableName WHERE columnName BETWEEN 20 AND 30;

SELECT columnName FROM tableName WHERE columnName >= 20 AND columnName <= 30; Docsity.com