oracle 10g.doc

Embed Size (px)

Citation preview

  • 8/9/2019 oracle 10g.doc

    1/6

    Using DDL Statements to Create and Mange Tables

    Create Table Statement

    Must have

    o Create table privilege

    o A storage area

    You specify

    o Table name

    o Column name, column data type and column sie!

    "! C#$AT$ TA%L$ &SC'$MA!( TA%L$)AM$

    *! +CLUM))AM$- DATATY.$-+CLUM) S/0$1, CLUM))AM$- DATATY.$ -+CLUM) S/0$112

    $3ample4

    C#$AT$ TA%L$ dept +deptno )UM%$#+*1, dname 5A#C'A#*+"61, loc 5A#C'A#*+"71,

    create8date DAT$ D$9AULT SYSDAT$12

    Describe the data structure

    D$SC#/%$ dept2

    Default ption4 specify a default value for a column during an insert

    Literal values, e3pressions, or S:L functions are legal values!

    The default data type must match the column data type!

    $3ample4

    C#$AT$ TA%L$ hire8dates +id )UM%$#+;1, hire8date DAT$ D$9AULT SYSDAT$12

    /ncluding Constraints

    Constraints enforce rules at the table level!

    Constraints prevent the deletion of a table if there are dependencies!

    The follo

  • 8/9/2019 oracle 10g.doc

    2/6

    o U)/:U$

    o .#/MA#Y =$Y

    o 9#$/>) =$Y

    o C'$C=

    Create a constraint at either of the follo

  • 8/9/2019 oracle 10g.doc

    3/6

    emp8dept8fB 9#$/>) =$Y +department8id1 #$9$#$)C$S

    departments+ department8id1, C)ST#A/)T emp8email8uB U)/:U$+email112

    Column level

    C#$AT$ table employees +@!!, department8id )UM%$#+61 C)ST#A/)T

    emp8deptid8fB #$9$#$)C$S departments+department8id1,@12

    9oreign Bey constraint4 Bey a table

    All data and structure in the table are deleted!

    Any pending transaction are committed

  • 8/9/2019 oracle 10g.doc

    4/6

    All inde3es are dropped

    All constraints are dropped

    You cannot roll bacB the D#. table statement!

    $3ample4

    D#. table dept2

    Manipulating DATA ;

    /)S$#T statement4

    /nsert a ne< ro< containing values for each column!

    List values in the default order of the columns in the table!

    ptionally, list the columns in the insert clause!

    $nclose character and date values in single Iuotation marBs!

    /)S$#T /)T dep +department8id, department8name, manager8id, location8id1

    5A=U$S +J, K.ublic #elations, ", "J12

    /mplicit method4 mit the column from the column list!

    /)S$#T /)T dep +department8id, department8name1 5A=U$S +7, K.ublic

    #elations12

    $3plicit Method4 Specify the )ULL Bey

  • 8/9/2019 oracle 10g.doc

    5/6

    Grite your /)S$#T statement

  • 8/9/2019 oracle 10g.doc

    6/6

    ALT$# table statement

    Use the ALT$# TA%L$ statement to4

    Add a ne< column

    Modify an e3isting column

    De?ne a default value of the ne< column

    Drop a column

    ALT$# table lol add+address varchar*+"112

    ALT$# table lol modify +address varchar*+712