Foreign Language Specialized

download Foreign Language Specialized

of 19

Transcript of Foreign Language Specialized

  • 8/3/2019 Foreign Language Specialized

    1/19

    Foreign

    Language

    Specia

    lizedLecturer:

    Student

    :1.Ngo

    Vu

    Linh

    2. LeVa

    nLinh

    aTanDat

    4.Tra

    nQuan

    gNhu

    5. DangV

    anHoai

    6.VoN

    gocThu

    Mr.Duyet

  • 8/3/2019 Foreign Language Specialized

    2/19

    SQL is a standard language for accessing

    and manipulating databases.

  • 8/3/2019 Foreign Language Specialized

    3/19

    What isSQL?

    SQL stands for Structured QueryLanguage

    SQL lets you access and manipulate

    databases SQL is an ANSI (American National

    Standards Institute) standard

  • 8/3/2019 Foreign Language Specialized

    4/19

    What Can SQLdo?

    SQL can execute queries against a database

    SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database

    SQL can create new databases SQL can create new tables in a database SQL can create stored procedures in a database SQL can create views in a database SQL can set permissions on tables, procedures,

    and viewsq SQL can be divided into two parts: The Data

    Manipulation Language (DML) and the Data

    Definition Language (DDL).

  • 8/3/2019 Foreign Language Specialized

    5/19

    q The query and update commands

    form the DML part of SQL:

    SELECT- extracts data from a database

    UPDATE - updates data in a database

    DELETE - deletes data from a database

    INSERT INTO - inserts new data into a

    database

    What Can SQLdo?

  • 8/3/2019 Foreign Language Specialized

    6/19

    q The DDL part of SQL permits database

    tables to be created or deleted. It alsodefines indexes (keys), specifies linksbetween tables, and imposes constraintsbetween tables. The most important DDL

    statements in SQL are:

    What Can SQLdo?

    CREATE DATABASE - creates a new database ALTER DATABASE - modifies a database CREATE TABLE - creates a new table

    ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX- creates an index (search

    key) DROP INDEX- deletes an index

  • 8/3/2019 Foreign Language Specialized

    7/19

    The SQL SELECT Stateme

    q

    The SELECT statement is used to select data from adatabase.

    q The result is stored in a result table, called the

    result-set

    SQL SELECT Syntax

    SELECT column_name(s)FROM table_name

    and

    SELECT * FROM table_name

    Note: SQL is not case sensitive. SELECT is the sameas select.

  • 8/3/2019 Foreign Language Specialized

    8/19

    An SQL SELECTExample

  • 8/3/2019 Foreign Language Specialized

    9/19

    SELECT * Exampl

    q Now we want to select all the columns from the

    "Persons" table.q We use the following SELECT statement:

    SELECT * FROM Persons

    Tip: The asterisk (*) is a quick way of selecting allcolumns!

    q The result-set will look like this:

  • 8/3/2019 Foreign Language Specialized

    10/19

    Navigation in aResult-set

    q Most database software systems allow navigation inthe result-set with programming functions, like:Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, etc.

    q Programming functions like these are not a part ofthis tutorial. To learn about accessing data withfunction calls, please visit ourADO tutorial or ourPHP tutorial.

    http://w3schools.com/ado/default.asphttp://w3schools.com/php/default.asphttp://w3schools.com/php/default.asphttp://w3schools.com/ado/default.asp
  • 8/3/2019 Foreign Language Specialized

    11/19

    The INSERT INTO Stateme

    q The INSERT INTO statement is used toinsert a new row in a table.

    q The INSERT INTO statement is used toinsert new records in a table.

  • 8/3/2019 Foreign Language Specialized

    12/19

    SQL INSERT INTO Synt

    q It is possible to write the INSERT INTO statementin two forms.

    q The first form doesn't specify the column names

    where the data will be inserted, only their values:q INSERT INTO table_name

    VALUES (value1, value2, value3,...)q The second form specifies both the column names

    and the values to be inserted:q INSERT INTO table_name (column1, column2,

    column3,...)VALUES (value1, value2, value3,...)

  • 8/3/2019 Foreign Language Specialized

    13/19

    SQL INSERT INTO Examp

    We have the following "Persons" table:

    q Now we want to insert a new row in the"Persons" table.

  • 8/3/2019 Foreign Language Specialized

    14/19

    q We use the following SQL statement:

    INSERT INTO PersonsVALUES (4,'Nilsen', 'Johan', 'Bakken 2','Stavanger')

    q The "Persons" table will now look like this:

    SQL INSERT INTO Examp

  • 8/3/2019 Foreign Language Specialized

    15/19

    Insert Data Only in Specified Colu

    q It is also possible to only add data in specific

    columns.q The following SQL statement will add a new row,

    but only add data in the "P_Id", "LastName" and

    the "FirstName" columns:q INSERT INTO Persons (P_Id, LastName, FirstName)

    VALUES (5, 'Tjessem', 'Jakob')

    The "Persons" table will now look like this:

  • 8/3/2019 Foreign Language Specialized

    16/19

    The CREATE TABLE Stateme

    q

    The CREATE TABLE statement is used to create atable in a database.SQL CREATE TABLE SyntaxCREATE TABLE table_name(

    column_name1 data_type,column_name2 data_type,column_name3 data_type,....

    )q The data type specifies what type of data thecolumn can hold. For a complete reference of allthe data types available in MS Access, MySQL,and SQL Server, go to our complete

    Data Types reference.

    C

    http://w3schools.com/sql/sql_datatypes.asphttp://w3schools.com/sql/sql_datatypes.asp
  • 8/3/2019 Foreign Language Specialized

    17/19

    CREATE TABLE Examp

    q Now we want to create a table called "Persons"

    that contains five columns: P_Id, LastName,

    FirstName, Address, and City.

    q We use the following CREATE TABLE statement:

    q CREATE TABLE Persons

    (

    P_Id int,

    LastName varchar(255),

    FirstName varchar(255),

    Address varchar(255),

    City varchar(255)

    CREATE TABLE E

  • 8/3/2019 Foreign Language Specialized

    18/19

    q The P_Id column is of type int and will hold a

    number. The LastName, FirstName, Address, and

    City columns are of type varchar with a maximum

    length of 255 characters.

    q The empty "Persons" table will now look like this:

    q The empty table can be filled with data with the

    INSERT INTO statement.

    CREATE TABLE Examp

  • 8/3/2019 Foreign Language Specialized

    19/19

    Thank You !