SlideShare una empresa de Scribd logo
1 de 24
Creating and Managing Tables
Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create tables Describe the datatypes that can be used when specifying column definition Alter table definitions Drop, rename, and truncate tables
Database Objects ObjectDescription TableBasic unit of storage; composed of rows  and columns View Logically represents subsets of data from    one or more tables Sequence Generates primary key values IndexImproves the performance of some queries Synonym Gives alternative names to objects
Naming Conventions Must begin with a letter Can be 1–30 characters long Must contain only A–Z, a–z, 0–9, _, $, and # Must not duplicate the name of another object owned by the same user Must not be an Oracle Server reserved word
The CREATE TABLE Statement You must have : CREATE TABLE privilege A storage area You specify: Table name Column name, column datatype, and column size CREATE TABLE [schema.]table 	    (columndatatype [DEFAULT expr][, ...]);
Referencing Another User’s Tables Tables belonging to other users are not in the user’s schema. You should use the owner’s name as a prefix to the table.
The DEFAULT Option Specify a default value for a column during an insert. … hiredate DATE DEFAULT SYSDATE, … ,[object Object]
Illegal values are another column’s name or pseudocolumn.
The default datatype must match the column datatype.,[object Object]
Tables in the Oracle Database User Tables Collection of tables created and maintained by the user Contain user information Data Dictionary Collection of tables created and maintained by the Oracle server Contain database information
Querying the Data Dictionary Describe tables owned by the user. SQL> SELECT	*  2FROMuser_tables; ,[object Object],SQL> SELECTDISTINCT object_type  2FROM user_objects; ,[object Object],SQL> SELECT	*  2FROMuser_catalog;
Datatypes DatatypeDescription VARCHAR2(size)	Variable-length character data CHAR(size)  	Fixed-length character data NUMBER(p,s)Variable-length numeric data DATE Date and time values LONG Variable-length character data up to 2 gigabytes CLOBSingle-byte character data up to 4gigabytes RAW and LONG RAW Raw binary data BLOBBinary data up to 4 gigabytes BFILEBinary data stored in an external file; up to 4 gigabytes
Creating a Table by Using a Subquery Create a table and insert rows by combining the CREATE TABLE statement and AS subquery option. Match the number of specified columns to the number of subquery columns. Define columns with column names anddefault values. CREATE TABLE table   	  [(column, column...)] AS subquery;
Creating a Table by Using a Subquery SQL> CREATE TABLE dept30 2AS 3SELECT   empno, ename, sal*12 ANNSAL, hiredate4FROM   emp5WHERE   deptno = 30; Table created. SQL> DESCRIBE dept30  Name                         Null?    Type  ---------------------------- -------- -----  EMPNO                        NOT NULL NUMBER(4)  ENAME                                 VARCHAR2(10)  ANNSAL                                NUMBER  HIREDATE                              DATE
The ALTER TABLE Statement Use the ALTER TABLE statement to: Add a new column Modify an existing column Define a default value for the new column ALTER TABLE table ADD		   (column datatype [DEFAULT expr] 		   [, column datatype]...); ALTER TABLE table MODIFY	   (column datatype [DEFAULT expr] 		   [, column datatype]...);
Adding a Column “…add a newcolumn intoDEPT30 table…” JOB DEPT30 New column  EMPNO ENAME       ANNSAL HIREDATE      ------ ----------	-------- 7698BLAKE3420001-MAY-81 7654MARTIN1500028-SEP-81 7499ALLEN1920020-FEB-81 7844TURNER1800008-SEP-81 ... JOB DEPT30  EMPNO ENAME       ANNSAL HIREDATE      ------ ----------	-------- 7698BLAKE3420001-MAY-81 7654MARTIN1500028-SEP-81 7499ALLEN1920020-FEB-81 7844TURNER1800008-SEP-81 ...
Adding a Column You use the ADD clause to add columns. SQL> ALTER TABLE dept30 2  ADD		   (job VARCHAR2(9)); Table altered. ,[object Object],    EMPNO ENAME         ANNSAL HIREDATE  JOB --------- ---------- --------- --------- ---- 7698 BLAKE          3420001-MAY-81 7654 MARTIN         1500028-SEP-81 7499 ALLEN          1920020-FEB-81 7844 TURNER         1800008-SEP-81 ... 6 rows selected.
Modifying a Column You can change a column’s datatype, size, and default value. A change to the default value affects only subsequent insertions to the table. ALTER TABLEdept30 MODIFY		(ename VARCHAR2(15)); Table altered.
Dropping a Table All data and structure in the table is deleted. Any pending transactions are committed. All indexes are dropped. You cannot roll back this statement. SQL> DROP TABLE dept30; Table dropped.
Changing the Name of an Object To change the name of a table, view, sequence, or synonym, you execute the RENAME statement. You must be the owner of the object. SQL> RENAME dept TO department; Table renamed.
Truncating a Table The TRUNCATE TABLE statement: Removes all rows from a table Releases the storage space used by that table You cannot roll back row removal when using TRUNCATE. Alternatively, you can remove rows by using the DELETE statement. SQL> TRUNCATE TABLE department; Table truncated.
Adding Comments to a Table You can add comments to a table or column by using the COMMENT statement. Comments can be viewed through the data dictionary views. ALL_COL_COMMENTS USER_COL_COMMENTS ALL_TAB_COMMENTS USER_TAB_COMMENTS SQL> COMMENT ON TABLE emp  2  IS 'Employee Information'; Comment created.
Summary Statement Description CREATE TABLE Creates a table  ALTER TABLE Modifies table structures  DROP TABLE Removes the rows and table structure RENAME Changes the name of a table, view, sequence, or synonym TRUNCATE Removes all rows from a table and releases the storage space COMMENT Adds comments to a table or view
Practice Overview Creating new tables Creating a new table by using the CREATE TABLE AS syntax Modifying column definitions Verifying that the tables exist Adding comments to a tables Dropping tables Altering tables

Más contenido relacionado

La actualidad más candente (19)

Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Ddl commands
Ddl commandsDdl commands
Ddl commands
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
8. sql
8. sql8. sql
8. sql
 
Oracle: PLSQL Commands
Oracle: PLSQL CommandsOracle: PLSQL Commands
Oracle: PLSQL Commands
 
Assignment#02
Assignment#02Assignment#02
Assignment#02
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
Les01
Les01Les01
Les01
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
Sql commands
Sql commandsSql commands
Sql commands
 
Les12
Les12Les12
Les12
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 

Similar a Les10 Creating And Managing Tables

SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10Umair Amjad
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Achmad Solichin
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tablessiavosh kaviani
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...SakkaravarthiS1
 
e computer notes - Creating and managing tables
e computer notes -  Creating and managing tablese computer notes -  Creating and managing tables
e computer notes - Creating and managing tablesecomputernotes
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptxSiddhantBhardwaj26
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 

Similar a Les10 Creating And Managing Tables (20)

Les09
Les09Les09
Les09
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
 
Les09
Les09Les09
Les09
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Module 3
Module 3Module 3
Module 3
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
e computer notes - Creating and managing tables
e computer notes -  Creating and managing tablese computer notes -  Creating and managing tables
e computer notes - Creating and managing tables
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
SQL
SQLSQL
SQL
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Database
Database Database
Database
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Lab
LabLab
Lab
 

Más de NETsolutions Asia: NSA – Thailand, Sripatum University: SPU (11)

Workshop_BDATools-MSAzure.pdf
Workshop_BDATools-MSAzure.pdfWorkshop_BDATools-MSAzure.pdf
Workshop_BDATools-MSAzure.pdf
 
Managing Big Data with Apache Hadoop.pdf
Managing Big Data with Apache Hadoop.pdfManaging Big Data with Apache Hadoop.pdf
Managing Big Data with Apache Hadoop.pdf
 
Introduction-Management NoSQL with MongoDB.pdf
Introduction-Management NoSQL with MongoDB.pdfIntroduction-Management NoSQL with MongoDB.pdf
Introduction-Management NoSQL with MongoDB.pdf
 
Les12 creating views
Les12 creating viewsLes12 creating views
Les12 creating views
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
Les06 Subqueries
 
Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 

Último

Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...Amil Baba Company
 
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtSHot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtSApsara Of India
 
ViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcE
ViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcEViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcE
ViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcEApsara Of India
 
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal EscortsCall Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal EscortsApsara Of India
 
Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)
Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)
Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)dollysharma2066
 
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...First NO1 World Amil baba in Faisalabad
 
Gripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to MissGripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to Missget joys
 
Call Girl Contact Number Andheri WhatsApp:+91-9833363713
Call Girl Contact Number Andheri WhatsApp:+91-9833363713Call Girl Contact Number Andheri WhatsApp:+91-9833363713
Call Girl Contact Number Andheri WhatsApp:+91-9833363713Sonam Pathan
 
1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdf1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdfTanjirokamado769606
 
High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...
High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...
High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...Riya Pathan
 
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCRdollysharma2066
 
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...Riya Pathan
 
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near MePrivate Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near MeRiya Pathan
 
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Riya Pathan
 
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170Sonam Pathan
 
Call Girls Near Delhi Pride Hotel New Delhi 9873777170
Call Girls Near Delhi Pride Hotel New Delhi 9873777170Call Girls Near Delhi Pride Hotel New Delhi 9873777170
Call Girls Near Delhi Pride Hotel New Delhi 9873777170Sonam Pathan
 
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa EscortsCash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa EscortsApsara Of India
 
The Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty VixenThe Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty VixenSalty Vixen Stories & More
 
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.comKolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.comKolkata Call Girls
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort ServicesApsara Of India
 

Último (20)

Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
Amil Baba in Pakistan Kala jadu Expert Amil baba Black magic Specialist in Is...
 
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtSHot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
 
ViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcE
ViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcEViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcE
ViP Call Girls In Udaipur 9602870969 Gulab Bagh Escorts SeRvIcE
 
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal EscortsCall Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
Call Girls In Karnal O8860008073 Sector 6 7 8 9 Karnal Escorts
 
Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)
Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)
Call US '' 8377087607'' !! Call Girls In Model Town Metro (Delhi NCR)
 
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
Authentic No 1 Amil Baba In Pakistan Authentic No 1 Amil Baba In Karachi No 1...
 
Gripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to MissGripping Adult Web Series You Can't Afford to Miss
Gripping Adult Web Series You Can't Afford to Miss
 
Call Girl Contact Number Andheri WhatsApp:+91-9833363713
Call Girl Contact Number Andheri WhatsApp:+91-9833363713Call Girl Contact Number Andheri WhatsApp:+91-9833363713
Call Girl Contact Number Andheri WhatsApp:+91-9833363713
 
1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdf1681275559_haunting-adeline and hunting.pdf
1681275559_haunting-adeline and hunting.pdf
 
High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...
High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...
High Profile Call Girls Sodepur - 8250192130 Escorts Service with Real Photos...
 
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in Patel Nagar Delhi NCR
 
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
 
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near MePrivate Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bansdroni - 8250192130 | 24x7 Service Available Near Me
 
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
 
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
Call Girls Near Taurus Sarovar Portico Hotel New Delhi 9873777170
 
Call Girls Near Delhi Pride Hotel New Delhi 9873777170
Call Girls Near Delhi Pride Hotel New Delhi 9873777170Call Girls Near Delhi Pride Hotel New Delhi 9873777170
Call Girls Near Delhi Pride Hotel New Delhi 9873777170
 
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa EscortsCash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
Cash Payment Contact:- 7028418221 Goa Call Girls Service North Goa Escorts
 
The Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty VixenThe Fine Line Between Honest and Evil Comics by Salty Vixen
The Fine Line Between Honest and Evil Comics by Salty Vixen
 
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.comKolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
 

Les10 Creating And Managing Tables

  • 2. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create tables Describe the datatypes that can be used when specifying column definition Alter table definitions Drop, rename, and truncate tables
  • 3. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns View Logically represents subsets of data from one or more tables Sequence Generates primary key values IndexImproves the performance of some queries Synonym Gives alternative names to objects
  • 4. Naming Conventions Must begin with a letter Can be 1–30 characters long Must contain only A–Z, a–z, 0–9, _, $, and # Must not duplicate the name of another object owned by the same user Must not be an Oracle Server reserved word
  • 5. The CREATE TABLE Statement You must have : CREATE TABLE privilege A storage area You specify: Table name Column name, column datatype, and column size CREATE TABLE [schema.]table (columndatatype [DEFAULT expr][, ...]);
  • 6. Referencing Another User’s Tables Tables belonging to other users are not in the user’s schema. You should use the owner’s name as a prefix to the table.
  • 7.
  • 8. Illegal values are another column’s name or pseudocolumn.
  • 9.
  • 10. Tables in the Oracle Database User Tables Collection of tables created and maintained by the user Contain user information Data Dictionary Collection of tables created and maintained by the Oracle server Contain database information
  • 11.
  • 12. Datatypes DatatypeDescription VARCHAR2(size) Variable-length character data CHAR(size) Fixed-length character data NUMBER(p,s)Variable-length numeric data DATE Date and time values LONG Variable-length character data up to 2 gigabytes CLOBSingle-byte character data up to 4gigabytes RAW and LONG RAW Raw binary data BLOBBinary data up to 4 gigabytes BFILEBinary data stored in an external file; up to 4 gigabytes
  • 13. Creating a Table by Using a Subquery Create a table and insert rows by combining the CREATE TABLE statement and AS subquery option. Match the number of specified columns to the number of subquery columns. Define columns with column names anddefault values. CREATE TABLE table [(column, column...)] AS subquery;
  • 14. Creating a Table by Using a Subquery SQL> CREATE TABLE dept30 2AS 3SELECT empno, ename, sal*12 ANNSAL, hiredate4FROM emp5WHERE deptno = 30; Table created. SQL> DESCRIBE dept30 Name Null? Type ---------------------------- -------- ----- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) ANNSAL NUMBER HIREDATE DATE
  • 15. The ALTER TABLE Statement Use the ALTER TABLE statement to: Add a new column Modify an existing column Define a default value for the new column ALTER TABLE table ADD (column datatype [DEFAULT expr] [, column datatype]...); ALTER TABLE table MODIFY (column datatype [DEFAULT expr] [, column datatype]...);
  • 16. Adding a Column “…add a newcolumn intoDEPT30 table…” JOB DEPT30 New column EMPNO ENAME ANNSAL HIREDATE ------ ---------- -------- 7698BLAKE3420001-MAY-81 7654MARTIN1500028-SEP-81 7499ALLEN1920020-FEB-81 7844TURNER1800008-SEP-81 ... JOB DEPT30 EMPNO ENAME ANNSAL HIREDATE ------ ---------- -------- 7698BLAKE3420001-MAY-81 7654MARTIN1500028-SEP-81 7499ALLEN1920020-FEB-81 7844TURNER1800008-SEP-81 ...
  • 17.
  • 18. Modifying a Column You can change a column’s datatype, size, and default value. A change to the default value affects only subsequent insertions to the table. ALTER TABLEdept30 MODIFY (ename VARCHAR2(15)); Table altered.
  • 19. Dropping a Table All data and structure in the table is deleted. Any pending transactions are committed. All indexes are dropped. You cannot roll back this statement. SQL> DROP TABLE dept30; Table dropped.
  • 20. Changing the Name of an Object To change the name of a table, view, sequence, or synonym, you execute the RENAME statement. You must be the owner of the object. SQL> RENAME dept TO department; Table renamed.
  • 21. Truncating a Table The TRUNCATE TABLE statement: Removes all rows from a table Releases the storage space used by that table You cannot roll back row removal when using TRUNCATE. Alternatively, you can remove rows by using the DELETE statement. SQL> TRUNCATE TABLE department; Table truncated.
  • 22. Adding Comments to a Table You can add comments to a table or column by using the COMMENT statement. Comments can be viewed through the data dictionary views. ALL_COL_COMMENTS USER_COL_COMMENTS ALL_TAB_COMMENTS USER_TAB_COMMENTS SQL> COMMENT ON TABLE emp 2 IS 'Employee Information'; Comment created.
  • 23. Summary Statement Description CREATE TABLE Creates a table ALTER TABLE Modifies table structures DROP TABLE Removes the rows and table structure RENAME Changes the name of a table, view, sequence, or synonym TRUNCATE Removes all rows from a table and releases the storage space COMMENT Adds comments to a table or view
  • 24. Practice Overview Creating new tables Creating a new table by using the CREATE TABLE AS syntax Modifying column definitions Verifying that the tables exist Adding comments to a tables Dropping tables Altering tables