Sql
Upcoming SlideShare
Loading in...5
×
 

Sql

on

  • 1,080 views

TRIDENT ACADEMY OF TECHNOLOGY

TRIDENT ACADEMY OF TECHNOLOGY
CSE B (GROUP 1)

Statistics

Views

Total Views
1,080
Views on SlideShare
1,080
Embed Views
0

Actions

Likes
0
Downloads
26
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Sql Sql Presentation Transcript

  • RDBMS LAB-1Learning Objectives Introduction to SQL Concept of Table and Relation Oracle Classification of SQL Table Creation,Data Insertion,Data Retrieval,Table Structure Modification,Data Deletion and Table Deletion Prepared by: Akshaya Kumar Dash Sasmita Mishra Copyright@2012 Trident Academy of Technology 1
  • Structured Query Language(SQL) SQL is a database computer language designed for the retrieval and management of data in relational database. SQL is structured Query Language which is a computer language for storing, manipulating and retrieving data stored in relational database. SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server uses SQL as standard database language. Copyright@2012 Trident Academy of Technology 2
  • Why SQL•Allows users to access data in relational database management Systems.•Allow users to describe the data.•Allow users to define data in database and manipulate that data.•Allow to embed within other languages using SQL modules, libraries & pre-compilers.•Allow users to create and drop databases and tables.•Allow users to create view, stored procedure, functions in a database.•Allow users to set permissions on tables, procedures, and views Copyright@2012 Trident Academy of Technology 3
  • Requirements to learn Oracle SQL A Computer with following Softwares OS:Windows or LinuxDB:Oracle 9i or any other Higher version Copyright@2012 Trident Academy of Technology 4
  • BooksBeginnig SQL by Paul WiltonSQL Bible by Alex KriegelSQL for dummiesHead First SQLSQL,PL/SQL The Programming Language of Oracle by Ivan Bayross(Available in Library)You need not a buy a single book(only Bikalp is the lab classes or internet) Copyright@2012 Trident Academy of Technology 5
  • Oracle has grouped the commands of SQL into thefollowing five sublanguages.DDL(Data Definition Language):Create,Alter,Drop,Rename,TruncateDML(Data Manipulation Language)Insert,Update,DeleteDQL(Data Query Language)SelectDCL(Data Control Language)Grant,RevokeTCL(Transcation Control Language)Rollback,Savepoint Copyright@2012 Trident Academy of Technology 6
  • Relation and TablesIn relational database systems (DBS) data arerepresented using tables (relations). A queryissued against the DBS also results in a table. Atable has the following structure: Copyright@2012 Trident Academy of Technology 7
  • A table is uniquely identied by its name andconsists of rows that contain the storedinformation, each row containing exactly onetuple (or record).A table can have one or more columns.A column is made up of a column name and adata type, and it describes an attribute of thetuples. The structure of a table, also calledrelation schema, thus is dened by its attributes.The type of information to be stored in a table isdefined by the data types of the attributes at tablecreation time. Copyright@2012 Trident Academy of Technology 8
  • Oracle Data Typeschar(n): Fixed-length character data (string), n characters long. The maximum size for n is 255 bytes (2000 in Oracle8). Note that a string of type char is always padded on right with blanks to full length of n.Example: char(40)varchar2(n): Variable-length character string. The maximum size for n is 2000 (4000 in Oracle8). Only the bytes used for a string require storage.Example: varchar2(80)number(o, d): Numeric data type for integers and reals. o = overall number of digits, d = number of digits to the right of the decimal point.Maximum values: o =38, d= -84 to +127. Examples: number(8), number(5,2)Note that, e.g., number(5,2) cannot contain anything larger than 999.99without resulting in an error. Data types derived from number areint[eger], dec[imal], smallint and real.date: Date data type for storing date and time.The default format for a date is: DD-MMM-YY. Examples: Trident Academy of Technology Copyright@2012 13-OCT-94, 07-JAN-98 9
  • Create CommandCreate Command Syntax:CREATE TABLE table-name{Column-name-1 data-type-1 [constraint],Column-name-1 data-type-2 [constraint],Column-name-1 data-type-3 [constraint]};eg->CREATE TABLE student(regd_no number(10),student_name varchar2(30),cgpa decimal(5,3),branch varchar2(10),mob_no number(10)); Copyright@2012 Trident Academy of Technology 10
  • Describe Command will Display the columnnames and corressponding data types present inthe table.describe table-name;Desc table-name;eg:desc student Copyright@2012 Trident Academy of Technology 11
  • Insert CommandIt can be executed in the following three ways Insert into table-name values(value1,value2,....,valuen); Insert into table-name (col1,col2,...,coln) values (value1,value2,...,valuen); Insert into table-name values(&col1,&col2,...,&coln); Copyright@2012 Trident Academy of Technology 12
  • View the content of tableSELECT STATEMENT Syntax:SELECT col1,col2,col3,...,colnFROM table-1,...,table-n[WHERE condition][ORDER BY col1 [ASC|DESC] [, col2 [ASC| DESC] ...]]; Copyright@2012 Trident Academy of Technology 13
  • SELECT CONTINUED...The SELECT Clause lists the columns to display.The FROM clause lists the tables from which to obtain the dataThe WHERE clause specifies the condition or conditions that need to be satisfied by the rows of the tables indicated in the FROM clauseThe ORDER BY clause indicates the criterion or criteria used to sort rows that satisfy WHERE clause Copyright@2012 Trident Academy of Technology 14
  • Where ClauseThe Conditions are of the following formColumn-name comparisonoperator single-value Comparison Operators Description = Equal to <> Not equal to < Less than <= Less than or equal to > Greater than >= Greater than or equal to Copyright@2012 Trident Academy of Technology 15
  • ALTER COMMAND One can add a new column,drop an existing column,modify the datatype of a column,and drop the constraints using the following commands respectively. ALTER TABLE table_name ADD COLUMN_name datatype; ALTER TABLE table_name DROP COLUMN column_name; ALTER TABLE table_name MODIFY (column_name,datatype); ALTER TABLE table_name DROP CONSTRAINT constraint_name; Copyright@2012 Trident Academy of Technology 16
  • TRUNCATE COMMAND TRUNCATE will remove all the rows of a tableTRUNCATE TABLE table-name;Note: We cant truncate the rows of a table if there are referential integrity constraints for which this table is parent table. We cant roolback a TRUNCATE statement Copyright@2012 Trident Academy of Technology 17
  • DROP COMMANDDROP command will permanently delete the table with all its dataDROP TABLE table-name [CASCADE CONSTRAINT]; Copyright@2012 Trident Academy of Technology 18
  • Lab Assignment-1Create the follwing tables branch(branch_name,branch_city,assets) customer(customer_name,customer_street,customer _city) loan(loan_number,branch_name,amount) borrower(customer_name,loan_number) account(account_number,branch_name,balance) depositor(customer_name,account_number) Copyright@2012 Trident Academy of Technology 19
  • Assignment Continued.. Populate the branch table with the following data branch_name branch_city assets Brighton Brooklyn 7100000 Downtown Brooklyn 9000000 Mianus Horseneck 400000 North Town Rye 3700000 Perryridge Horseneck 1700000 Pownal Bennington 300000 Redwood Palo Alto 2100000 Round Hill Horseneck 8000000 Copyright@2012 Trident Academy of Technology 20
  • Assignment Continued.. Populate the customer table with the following data Customer_name Customer_street Customer_city Adams Spring Pittsfield Brooks Senator Brooklyn Curry North Rye Glenn Sand Hill Woodside Green Walnut Stamford Hayes Main Harrison Johnson Alma Palo Alto Jones Main Harrison Lindsay Park Pittsfield Smith North Rye Turner Putnam Stamford Williams Nassau Princeton Copyright@2012 Trident Academy of Technology 21
  • Assignment Continued.. Populate the loan table with the following data loan_number branch_name amount L-11 Round Hill 900 L-14 Downtown 1500 L-15 Perryridge 1500 L-16 Perryridge 1300 L-17 Downtown 1000 L-23 Redwood 2000 L-93 Mianus 500 Copyright@2012 Trident Academy of Technology 22
  • Assignment Continued... Populate the borrower realtion the following data Customer_name loan_number Adams L-16 Curry L-93 Hayes L-15 Jackson L-14 Jones L-17 Smith L-11 Smith L-23 Williams L-17 Copyright@2012 Trident Academy of Technology 23
  • Assignment Continued... Populate account relation with the following data account_number branch_name balance A-101 Downtown 500 A-215 Mianus 700 A-102 Perryridge 400 A-305 Round Hill 350 A-201 Brighton 900 A-222 Redwood 700 A-217 Brighton 750 Copyright@2012 Trident Academy of Technology 24
  • Assignment Continued... Populate the depositor relation with the following data Customer_name account_number Hayes A-102 Johnson A-101 Johnson A-201 Jones A-217 Lindsay A-222 Smith A-215 Turner A-305 Copyright@2012 Trident Academy of Technology 25
  • Create One more tableCreate a student table with the following data Regdno Student_name Branch 1001 Surya CSE 1002 Binaya ETC 1003 Arup CSE Add the CGPA Column, to the student table (the type must be a floating point type) Drop CGPA column Modify the existing type of regdno. Rename student to student_trident Now delete all the data present in the student_trident table. Drop the table Copyright@2012 Trident Academy of Technology 26
  • Thank YouCopyright@2012 Trident Academy of Technology 27