sql basic 1

Upload: ashleyrulzzzzzzz

Post on 01-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 SQL Basic 1

    1/8

    Experiment No. – 9, 10

    Aim: To Study SQL Basics.

    Teory:

    SQL is a standard language for accessing and manipulating databases.

    • SQL stands for Structured Query Language

    • SQL lets you access and manipulate databases

    • SQL is an ANSI (American National Standards Institute) standard

    What Can SQL do?

    • 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 ne databases

    • SQL can create ne tables in a database

    • SQL can create stored procedures in a database

    • SQL can create vies in a database

    • SQL can set permissions on tables! procedures! and vies

    RDBMS

    "#$%S stands for "elational #atabase %anagement System.

    "#$%S is t&e basis for SQL! and for all modern database systems suc& as %S SQL Server! I$% #$'!

    racle! %ySQL! and %icrosoft Access.&e data in "#$%S is stored in database ob*ects called tables.

    A table is a collection of related data entries and it consists of columns and ros.

    SQL DML and DDL

    SQL can be divided into to parts+ &e #ata %anipulation Language (#%L) and t&e #ata #efinition

    Language (##L).

    &e query and update commands form t&e #%L part of SQL+

    • SELE!T , extracts data from a database

    • "#$ATE , updates data in a database

    • $ELETE , deletes data from a database

    • %NSE&T %NT' , inserts ne data into a database

  • 8/9/2019 SQL Basic 1

    2/8

    &e ##L part of SQL permits database tables to be created or deleted. It also defines indexes (-eys)!

    specifies lin-s beteen tables! and imposes constraints beteen tables. &e most important ##L

    statements in SQL are+

    • !&EATE $ATABASE , creates a ne database

    • ALTE& $ATABASE , modifies a database

    • !&EATE TABLE , creates a ne table

    • ALTE& TABLE , modifies a table

    $&'# TABLE , deletes a table• !&EATE %N$E( , creates an index (searc& -ey)

    • $&'# %N$E( , deletes an index

    1.  The CREATE TABLE Statement

    &e "/A/ A$L/ statement is used to create a table in a database.

    SQL CREATE TABLE Syntax

    "/A/ A$L/ table0name

    (

    column0name1 data0type!

    column0name' data0type!

    column0name2 data0type!

    ....

    )

    &e data type specifies &at type of data t&e column can &old.

    SQL) !&EATE TABLE Students  * +%$ int,

      Name -arcar+100,

      / Branc -arcar+100,

      Ae int2

    Ta34e created.

  • 8/9/2019 SQL Basic 1

    3/8

    2.The SQL SELECT Statement

    &e S/L/ statement is used to select data from a database.

    &e result is stored in a result table! called t&e result,set.

    SQL SELECT Syntax

    S/L/ column0name(s)

    3"% table0name

    and

    S/L/ 4 3"% table0name

    SQL> select !"om st#dents$

    no "o%s selected

    &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&

    '.The ()SERT ()T* Statement

    &e INS/" IN statement is used to insert a ne ro in a table.

    SQL ()SERT ()T* Syntax

    It is possible to rite t&e INS/" IN statement in to forms.

    &e first form doesn5t specify t&e column names &ere t&e data ill be inserted! only t&eir values+

    INS/" IN table0name

    6AL7/S (value1! value'! value2!...)

    &e second form specifies bot& t&e column names and t&e values to be inserted+

  • 8/9/2019 SQL Basic 1

    4/8

    INS/" IN table0name (column1! column'! column2!...)

    6AL7/S (value1! value'! value2!...)

    SQL) insert into students

      * -a4ues+1,5sana5,5computer5,02

    1 ro6 created.

    SQL) insert into students+%$,Name,Branc,Ae

      * -a4ues+*,5seema5,5%T5,02

    1 ro6 created.

    SQL) se4ect 7 8rom Students2

      %$ NAE B&AN! A;E

  • 8/9/2019 SQL Basic 1

    5/8

    SQL) se4ect distinct Branc 8rom students2

    B&AN!

  • 8/9/2019 SQL Basic 1

    6/8

      * 6ere id?1 or Ae?*>2

    NAE

  • 8/9/2019 SQL Basic 1

    7/8

    Note: Notice t&e 89/"/ clause in t&e 7

    SQL) update students

      * set 3ranc?5ec5

      6ere name?5=on52

    1 ro6 updated.

    SQL) se4ect 7 8rom students2

      %$ NAE B&AN! A;E

  • 8/9/2019 SQL Basic 1

    8/8