Structured Query Language

50 339 0
Structured Query Language

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Structured Query Language Structured Query Language Introduction  SQL stands for “Structured Query Language.” SQL stands for “Structured Query Language.”  SQL is a language used to interact with the database. SQL is a language used to interact with the database.  SQL is a data access language. SQL is a data access language.  SQL is based on relational tuple calculus. SQL is based on relational tuple calculus.  SQL is a standard relational database management SQL is a standard relational database management language. language.  SQL commands consist of English-like statements which SQL commands consist of English-like statements which are used to query, insert, update, and delete data. are used to query, insert, update, and delete data.  SQL is referred to as nonprocedural database language. SQL is referred to as nonprocedural database language. Commands in SQL  SQL commands can be classified in to three types: SQL commands can be classified in to three types:  Data Definition Language commands (DDL)  Data Manipulation Language commands (DML)  Data Control Language commands (DCL)  DDL commands are used to define a database, including DDL commands are used to define a database, including creating, altering, and dropping tables and establishing creating, altering, and dropping tables and establishing constraints. constraints.  DML commands are used to maintain and query a database, DML commands are used to maintain and query a database, including updating, inserting, modifying, and querying data. including updating, inserting, modifying, and querying data.  DCL commands are used to control a database including DCL commands are used to control a database including administering privileges and saving of data. administering privileges and saving of data. Datatypes in SQL  In relational model the data are stored in the form of tables. A In relational model the data are stored in the form of tables. A table is composed of rows and columns.When we create a table is composed of rows and columns.When we create a table we must specify a datatype for each of its columns. table we must specify a datatype for each of its columns.  These datatypes define the domain of values that each These datatypes define the domain of values that each column can take. column can take.  Datatypes: Datatypes:  built-in  user-defined types  Some of the built-in datatypes are string datatype to store Some of the built-in datatypes are string datatype to store characters, number datatype to store numerical value, and characters, number datatype to store numerical value, and date and time datatype to store when the event happened date and time datatype to store when the event happened (history, date of birth, etc.). (history, date of birth, etc.). Datatypes in SQL  Char Char CHAR datatype to store fixed-length character data. CHAR datatype to store fixed-length character data. Maximum size = 2000 bytes Maximum size = 2000 bytes  Varchar Varchar Varchar datatype to store variable-length character data. Varchar datatype to store variable-length character data.  Number Number Number types let you store numeric data (integers, real Number types let you store numeric data (integers, real numbers, and floating-point numbers), represent numbers, and floating-point numbers), represent quantities, and do calculations. quantities, and do calculations. Datatypes in SQL  NChar NChar To store multi byte fixed length character data. Its same To store multi byte fixed length character data. Its same as Char only difference is it is used to store characters of as Char only difference is it is used to store characters of different language like Japenese , chinese etc. different language like Japenese , chinese etc. Number of characters it can store depend on language. Number of characters it can store depend on language.  NVarchar NVarchar To store multi byte variable length character data. Its To store multi byte variable length character data. Its same as Varchar2 only difference is it is used to store same as Varchar2 only difference is it is used to store characters of different language like Japenese , chinese characters of different language like Japenese , chinese etc. etc. Number of characters it can store depend on language. Number of characters it can store depend on language. Datatypes in SQL  Datetime Datetime DATETIME datatype to store fixed-length datetimes. DATETIME datatype to store fixed-length datetimes. Date range Date range from from 1753-1-1 to 9999-12-31. 1753-1-1 to 9999-12-31.  Smalldatetime Smalldatetime Date range from 1900-1-1 to 2079-6-6 Date range from 1900-1-1 to 2079-6-6  Money Money represent monetary or currency values. represent monetary or currency values. Data Definition Language (DDL)  The di erent structures that are created by DDL are ff The di erent structures that are created by DDL are ff Tables, Views, Sequences, Triggers, Indexes, etc. Tables, Views, Sequences, Triggers, Indexes, etc.  Tables Tables  It is a relation that is used to store records of related data. It is a logical structure maintained by the database manager.  It is made up of columns and rows.  At the intersection of every column and row there is a speciffic data item called a value.  A base table is created with the CREATE TABLE statement and is used to hold persistent user data. Create Table Command  Steps in Table Creation Steps in Table Creation  Identify datatypes for Identify datatypes for attributes attributes  Identify columns that can Identify columns that can and cannot be null and cannot be null  Identify columns that Identify columns that must be unique must be unique  Identify primary key– Identify primary key– foreign key mates foreign key mates  Determine default values Determine default values  Identify constraints on Identify constraints on columns (domain columns (domain specifications) specifications)  Create the table Create the table Sample Database [...]... , and so on) String comparisons (LIKE, NOT LIKE) Logical operators (AND, OR, NOT) Ranges (BETWEEN and NOT BETWEEN) Lists of values (IN and NOT IN) Unknown Values (IS NULL and IS NOT NULL) Exists in Subquery (EXISTS and NOT EXISTS) Use DISTINCT to eliminate duplicates [ TOP (expression) [PERCENT] [ WITH TIES ] ] Some Built-in functions           GETDATE(): Returns the current system date and... bar Typing the name of the alias One reason for using an alias is simplicity A second reason for using an alias is that it is needed when joining a table to itself, called a self-join Data Manipulation Language  Adding a New Row to the Table INSERT INTO table name VALUES (‘&column1-name’, ‘&column2-name’ &columnN-name)  Updating the Data in the Table UPDATE table name SET attribute value=new value... emp_fname='Anna ' SELECT Statement   Used for queries on single or multiple tables Clauses of the SELECT statement:       SELECT  List the columns (and expressions) that should be returned from the query FROM  Indicate the table(s) or view(s) from which data will be obtained WHERE  Indicate the conditions under which a row will be included in the result GROUP BY  Indicate categorization of results . Structured Query Language Structured Query Language Introduction  SQL stands for “Structured Query Language. ” SQL stands for “Structured Query Language. ”  SQL is a language used. and query a database, DML commands are used to maintain and query a database, including updating, inserting, modifying, and querying data. including updating, inserting, modifying, and querying. different language like Japenese , chinese etc. different language like Japenese , chinese etc. Number of characters it can store depend on language. Number of characters it can store depend on language.  NVarchar NVarchar To

Ngày đăng: 12/05/2014, 11:55

Từ khóa liên quan

Mục lục

  • Slide 1

  • Introduction

  • Commands in SQL

  • Datatypes in SQL

  • Slide 5

  • Slide 6

  • Slide 7

  • Data Definition Language (DDL)

  • Create Table Command

  • Sample Database

  • Slide 11

  • Slide 12

  • Slide 13

  • Sample Database

  • CREATE TABLE Command

  • Slide 16

  • DROP TABLE statement

  • Table Modification Commands

  • Imposition of Constraints

  • TRUNCATE TABLE command

Tài liệu cùng người dùng

Tài liệu liên quan