Structured Query Language(SQL)

  • View
    25

  • Download
    1

Embed Size (px)

DESCRIPTION

Structured Query Language(SQL). XU Yinqing SEEM PHD YEAR 3. Outline. SQL Statements Basic statements SQL functions SQLite: a SQL engine SQLite browser SQLite Manager: add-on for Firefox. What is SQL?. SQL stands for Structured Query Language - PowerPoint PPT Presentation

Text of Structured Query Language(SQL)

PowerPoint

Structured Query Language(SQL)XU YinqingSEEM PHD YEAR 3OutlineSQL StatementsBasic statementsSQL functionsSQLite: a SQL engineSQLite browserSQLite Manager: add-on for FirefoxWhat is SQL?

SQL stands for Structured Query LanguageSQL lets you access and manipulate databasesSQL is an ANSI (American National Standards Institute) standard

What Can SQL do?

SQL can execute queries against a databaseSQL can insert records in a databaseSQL can update records in a databaseSQL can delete records from a databaseSQL can create new databasesSQL can create new tables in a database

SQL is a Standard - BUT....

Although SQL is an ANSI (American National Standards Institute) standard, there are different versions of the SQL language.However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.

Using SQL in Your Web Site

To build a web site that shows data from a database, you will need:An RDBMS database program (i.e. MS Access, SQL Server, MySQL)To use a server-side scripting language, like PHP or ASPTo use SQL to get the data you wantTo use HTML / CSS

RDBMS

RDBMS stands for Relational Database Management System.RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.The data in RDBMS is stored in database objects called tables.A table is a collection of related data entries and it consists of columns and rows.

Database Tables

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry1

Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitucin 2222Mxico D.F.05021Mexico3Antonio Moreno TaqueraAntonio MorenoMataderos 2312Mxico D.F.05023Mexico4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK5Berglunds snabbkpChristina BerglundBerguvsvgen 8LuleS-958 22SwedenNoteSQL is NOT case sensitive: SELECT is the same as selectSemicolon after SQL Statements? Depend on the database systemSemicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.

Some of The Most Important SQL Commands

SELECT- extracts data from a databaseUPDATE- updates data in a databaseDELETE- deletes data from a databaseINSERT INTO- inserts new data into a databaseCREATE DATABASE- creates a new databaseALTER DATABASE- modifies a databaseCREATE TABLE- creates a new tableALTER TABLE- modifies a tableDROP TABLE- deletes a tableCREATE INDEX- creates an index (search key)DROP INDEX- deletes an index

SELECTSQL SELECT SyntaxSELECTcolumn_name,column_nameFROMtable_name;andSELECT * FROMtable_name;

Database Tables

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry1

Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitucin 2222Mxico D.F.05021Mexico3Antonio Moreno TaqueraAntonio MorenoMataderos 2312Mxico D.F.05023Mexico4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK5Berglunds snabbkpChristina BerglundBerguvsvgen 8LuleS-958 22SwedenSELECTThe following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table:SELECT CustomerName,City FROM Customers;The following SQL statement selects all the columns from the "Customers" table:SELECT * FROM Customers;SELECT DISTINCTThe DISTINCT keyword can be used to return only distinct (different) values.SQL SELECT DISTINCT SyntaxSELECT DISTINCTcolumn_name,column_nameFROMtable_name;EXAMPLE:SELECT DISTINCT City FROM Customers;Database Tables

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry1

Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitucin 2222Mxico D.F.05021Mexico3Antonio Moreno TaqueraAntonio MorenoMataderos 2312Mxico D.F.05023Mexico4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK5Berglunds snabbkpChristina BerglundBerguvsvgen 8LuleS-958 22SwedenWHERE The WHERE clause is used to filter records.The WHERE clause is used to extract only those records that fulfill a specified criterion.SQL WHERE SyntaxSELECTcolumn_name,column_nameFROMtable_nameWHEREcolumn_name operator value;

Database Tables

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry1

Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitucin 2222Mxico D.F.05021Mexico3Antonio Moreno TaqueraAntonio MorenoMataderos 2312Mxico D.F.05023Mexico4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK5Berglunds snabbkpChristina BerglundBerguvsvgen 8LuleS-958 22SwedenWHEREThe following SQL statement selects all the customers from the country "Mexico", in the "Customers" table:SELECT * FROM CustomersWHERE Country='Mexico';

Operators in The WHERE Clause

OperatorDescription=Equal

Not equal.Note:In some versions of SQL this operator may be written as !=>Greater than=Greater than or equal New Database

SQLite Managerhttps://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/How to create table?

Database-> New DatabaseTable-> Create Table

EndThank you !