INTRODUCTION TO DATABASE

Similar documents
STRUCTURED QUERY LANGUAGE (SQL)

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

Creating and Managing Tables Schedule: Timing Topic

The Structured Query Language Get Started

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

Relational Database Language

Data about data is database Select correct option: True False Partially True None of the Above

Data Base Concepts. Course Guide 2

Full file at

SQL. History. From Wikipedia, the free encyclopedia.

Lab # 4. Data Definition Language (DDL)

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Introduction to Computer Science and Business

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Introduction. Introduction to Oracle: SQL and PL/SQL

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

Chapter 9: Working with MySQL

Chapter-14 SQL COMMANDS

PL/SQL Block structure

SQL Interview Questions

Course Outline and Objectives: Database Programming with SQL

Introduction to Computer Science and Business

Course Logistics & Chapter 1 Introduction

Chapter 1 SQL and Data

Database Programming with SQL

Oracle. SQL(Structured Query Language) Introduction of DBMS. Build In Function. Introduction of RDBMS. Grouping the Result of a Query

Full file at

1 Overview of Database Management

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

EDUVITZ TECHNOLOGIES

DB Creation with SQL DDL

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

CHAPTER. Introduction

Database Management System. Fundamental Database Concepts

Sample Question Paper

Downloaded from

Database Management System 9

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,

M.C.A. (CBCS) Sem.-III Examination November-2013 CCA-3004 : Database Concepts and Tools. Faculty Code: 003 Subject Code:

JSPM s Bhivarabai Sawant Institute of Technology & Research, Wagholi, Pune Department of Information Technology

Review -Chapter 4. Review -Chapter 5

Bonus Content. Glossary

Creating SQL Tables and using Data Types

@vmahawar. Agenda Topics Quiz Useful Links

CHAPTER. Introduction

CS Final Exam Review Suggestions

Mahathma Gandhi University

5. Single-row function

Oracle SQL & PL SQL Course

Deccansoft softwareservices-microsoft Silver Learing Partner. SQL Server Syllabus

SQL Commands & Mongo DB New Syllabus

1 Prepared By Heena Patel (Asst. Prof)

Today Learning outcomes LO2

An Effective Approach to Improve Storage Efficiency Using Variable bit Representation

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time

Instructor: Craig Duckett. Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE

Part VII Data Protection

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Basant Group of Institution

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

COMP 3400 Mainframe Administration 1

Business Analytics. SQL PL SQL [Oracle 10 g] P r i n c e S e t h i w w w. x l m a c r o. w e b s. c o m

2 PL/SQL - fundamentals Variables and Constants Operators SQL in PL/SQL Control structures... 7

Advanced SQL Tribal Data Workshop Joe Nowinski

Question: Which statement would you use to invoke a stored procedure in isql*plus?


G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

UNIT-IV (Relational Database Language, PL/SQL)

Fundamentals of Information Systems, Seventh Edition

Sql Server Syllabus. Overview

Transforming ER to Relational Schema

Database Systems CSE 303. Lecture 02

Database Systems CSE 303. Lecture 02

ORACLE Developed By: Jignesh Dhol

SQL Structured Query Language Introduction

G64DBS Database Systems. G64DBS Module. Recommended Textbook. Assessment. Recommended Textbook. Recommended Textbook.

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

Oracle Database 12c SQL Fundamentals

Proje D2K. CMM (Capability Maturity Model) level Project Standard:- Corporate Trainer s Profile

GridDB Advanced Edition SQL reference

Table of Contents. Oracle SQL PL/SQL Training Courses

What is Data? ANSI definition: Volatile vs. persistent data. Data. Our concern is primarily with persistent data

What is Data? Volatile vs. persistent data Our concern is primarily with persistent data

Database Systems Overview. Truong Tuan Anh CSE-HCMUT

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

A <column constraint> is a constraint that applies to a single column.

How to define a relational schema for a data base?

Chapter 4: SQL Basics

Introduction to Database Concepts. Department of Computer Science Northern Illinois University January 2018

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

SQL DATA MANIPULATION. Prepared By: Dr. Vipul Vekariya.

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

Copyright 2004 Pearson Education, Inc.

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

Database Management Systems

Transcription:

1 INTRODUCTION TO DATABASE DATA: Data is a collection of raw facts and figures and is represented in alphabets, digits and special characters format. It is not significant to a business. Data are atomic level pieces of information. They does not help in decision making. Example: 23 is data, Ankit is data. DATABASE: A Database is a collection of related data or information stored so that it is available to many users for different purposes. Generally it is nothing but a computerised record keeping system. A Database has the following properties: a) It represents some aspects of real world. b) It has some meaning. c) A database is designed, builds and populated with data for a specific purpose. Examples of database are: 1) Bank 2) Hospital 3) University 4) Library 5) Dictionary 6) Phone Book 7) Log Book.

2 DATABASE MANAGEMENT SYSTEM (DBMS): To be able to successfully design and maintain databases we have to do the following: a) Identify which part of the world s data is of interest to us. b) Identify what specific objects in that part of the world s data are of interest. c) Identify a relationship between the objects. Hence, the objects, their attributes and the relationship between them (that are of interest to us) are stored in the database that is designed, built and populated with data for a specific purpose. Software houses took up the challenge of designing a system that would help in managing data in such a database. These systems were called Database Management Systems (DBMS). DBMS is a system that allows inserting, updating, deleting and processing of data. Some of DBMS developed by software houses were Oracle, Ingress, Sybase, Dbase 3+, Foxbase, Fox pro, MS Access, Database, Data flex, Advanced Revelation, and so on. Benefits of DBMS: a) The amount of data redundancy in stored data can be reduced. b) No more data inconsistencies. c) Stored data can be shared by a single or multiple users. d) Standards can be set and followed. e) Data integrity can be maintained. Data integrity refers to the problem of ensuring that database contains only accurate data. f) Security of data can be simply implemented. g) Data independence can be achieved, i.e. data and programs that manipulate the data are two different entities.

3 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL): Structured Query Language (SQL) is a language that provides an interface to relational database systems. SQL was developed by IBM in the 1970s for use in system R, and is a de facto standard, as well as an ISO and ANSI standard. SQL is often pronounced SEQUEL. In common usage, SQL also encompasses DML (Data Manipulation Language), for INSERTs, UPDATEs, DELETs and DDL (Data Definition Language), used for creating and modifying tables and other database structures. The development of SQL is governed by standards. The American National Standers Institute (ANSI) is an organization that approves certain standards in many different industries. SQL has been deemed the standard language in relational database communication, originally approved in 1986 based on IBM s implementation. In 1987, the International Standards Organization (ISO) accepted the ANSI SQL standard as the international standard. The standard was revised again in 1992 and was called SQL-92. The newest standard is now called SQL-99; it is also referred to as SQL-3. SQL-3 support objects extensions and are partially implemented in Oracle8 and 9. SQL has been a command language for communication with the Oracle 9i Server from any tool or application. Oracle SQL contains many extensions. When an SQL statement is entered, it is stored in a part of memory called the SQL buffer and remains there until a new SQL statement is entered. SQL *PLUS is an Oracle tool that recognizes and submits SQL statements to the Oracle 9i Server for execution. It contains its own command language.

4 FEATURES OF SQL: a) SQL can be used by a range of users, including those with little or no programming experience. b) It is a non procedural language. c) It reduces the amount of time required for creating and maintaining systems. d) It is an English-like language. FEATURES OF SQL *PLUS: a) SQL *PLUS accepts ad hoc entry of statements. b) It accepts SQL inputs from files. c) It provides a line editor for modifying SQL statements. d) It controls environmental settings. e) It formats Query results into basic reports. f) It accesses local and remote databases. COMPONENTS OF SQL: 1) DDL (Data Definition Language) : It is a set of SQL commands used to create, modify and delete database structures but not data. These commands are normally not used by a general user, who should be accessing the database via an application. They are normally used by the DBA (Database Administrator) to a limited extent, a database designer or application developer. These statements are immediate i.e. they are not susceptible to ROLLBACK commands. It should also be noted that if several DML statements for example updates are executed then issuing any DDL command would COMMIT all the updates as every

5 DDL command implicitly issues a COMMIT command to the database. Anybody using DDL must have the CREATE object privilege and a table space area in which to create objects. DDL: Data Definition Statements Examples: CREATE To create objects in the database. ALTER Alters the structure of the database. DROP Delete objects from the database. TRUNCATE Remove all records from a table, including all spaces allocated for the records are removed. COMMENT Add comments to the data dictionary. GRANT Gives user s access privileges given with the GRANT command. 2) DML (Data Manipulation Language) : It is the area of SQL that allows changing data within the database. Data manipulation involves retrieval of data from the database, insertion of new data in the database, deletion and modification of existing data in the database. DML provides commands to select and retrieve data from the database. Retrieval of data is known as QUERY of data. DML: Data Manipulation Language Statements Examples: INSERT Insert data into a table. UPDATE Updates existing data within a table. DELETE Deletes all records from a table, the space for the records remains. CALL Call a PL/SQL or Java subprogram. EXPLAIN PLAN Explain access path to data. LOCK TABLE control concurrency.

6 3) DCL (Data Control Language) : It is the component of SQL statement that control access to data and to the database. Occasionally DCL statements are grouped with DML statements. DCL: Data Control Statements Examples: COMMIT Save work done. SAVEPOINT Identify a point in a transaction to which you can later roll back. ROLLBACK Restore database to original since the last COMMIT. SET TRANSACTION Change transactions options like what roll back segment to use. GRANT / REVOKE Grant or take back permissions to or from the oracle users. 4) DQL (Data Query Language) : It is the component of SQL statement that allows getting data from the database and imposing ordering upon it. It includes the SELECT statement. This command is the heart of SQL. It allows getting the data out of the database, perform operations with it. When a SELECT is fired against a table or tables the result is compiled into a further temporary table, which is displayed or perhaps received by the program i.e. a front end. DQL: Data Query Language Statements Examples: SELECT Retrieve data from a database.

7 SQL V/s SQL *PLUS SQL SQL is a language for communicating with the Oracle Server to access data SQL is based on American National Standards Institute (ANSI) standard SQL SQL manipulates data and table definitions in the database SQL is entered into the SQL buffer on one or more lines SQL does not have a continuation character It cannot be abbreviated SQL uses a termination character to execute commands immediately SQL uses functions to perform some formatting SQL *PLUS SQL *PLUS recognizes SQL statements and sends them to the Server SQL *PLUS is the Oracle proprietary interface for executing SQL statements SQL *PLUS does not allow manipulation of values in the database SQL *PLUS is entered one line at a time, not stored in the SQL buffer SQL *PLUS uses a dash (-) as a continuation character if the command is longer than one line It can be abbreviated SQL *PLUS does not require termination characters; executes commands immediately SQL *PLUS uses commands to format data

8 DATA TYPES USED IN SQL Basic Data Types : Data types come in several forms and sizes, allowing the programmer to create tables suited to the scope of the project. The decisions made in choosing proper data types greatly influence the performance of a database, so it is wise to have a detailed understanding of these concepts. Oracle is capable of many of the data types that even the novice programmer has probably already been exposed to. The table below includes some of the more commonly used: Data Type CHAR(size) VARCHAR (size) Description This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters the cell can hold. The maximum number of characters (i.e. the size) this data type can hold is 255 characters. The data held is right padded with spaces to whatever length specified. For example : In case of Name CHAR(60) if the data held in variable name is only 20 characters in length, then the entry will be padded with 40 characters worth of spaces. These spaces will be removed when the value is retrieved though. These entries will be stored and compared by My SQL in case-insensitive fashions unless the BINARY keyword is associated with it. The BINARY attribute means that column values are stored and compared in case-sensitive fashion using the underlying character code values rather than a lexical ordering. BINARY doesn t effect how the column is stored or retrieved. This data type is used to store variable length alphanumeric data. It is a more flexible form of the

9 VARCHAR 2 (size) DATE CHAR data type. The maximum this data type can hold up to 4000 characters. One difference between this type and the CHAR data type is ORACLE compares VARCHAR values using non padded comparison semantics i.e. the inserted values will not be padded with spaces. It also represents data of type string, yet stores this data in variable length format. VARCHAR can hold 1 to 255 characters. VARCHAR is usually a wiser choice than CHAR, due to it s variable length format characteristic. But, keep in mind, that CHAR is much faster than VARCHAR, sometimes up to 50%. This date type is used to represent date and time. The standard format is DD-MON-YY as in 03-FEB-08. To enter dates other than the standard format, use the appropriate functions. Date Time stores date in the 24- hour format. By default, the time in a date field is 12:00:00 am, if no time portion is specified. The default date for a date field is the first day of the current month. Valid dates range from January 1, 4712 B.C. to December 31, 4712 A.D. NUMBER (P,S) The NUMBER data type is used to store numbers (fixed or floating point). Numbers of virtually any magnitude maybe stored up to 38 digits of precision. Valid values are 0, and positive and negative numbers with magnitude 1.0E-13 to 9.9...E125. Numbers may be expressed in two ways : first, with the numbers 0 to 9, the signs + and -, and a decimal point (.); second, in scientific notation, such as, 1.85E3 for 1850. The precision (P), determines the maximum length of the data, whereas the scale (S), determines the number of places to the right of the decimal. If scale is omitted then the default is zero. If precision is omitted, values are stored with their original precision up to the maximum of 38 digits. LONG This data type is used to store variable length character strings containing up to 2GB. LONG data can be used to store arrays of binary data in ASCII format. Only one long value can be defined per table. LONG values cannot be used in sub queries, functions, expressions, where clauses or indexes and the normal character functions such as SUBSTR

10 cannot be applied to LONG values. A table containing a LONG value cannot be clustered. RAW / LONG RAW The RAW / LONG RAW data types are used to store the binary data, such as digitized picture or image. Data loaded into columns of these data types are stored without any further conversion. RAW data type can have a maximum length of 255 bytes. LONG RAW data type can contain up to 2 GB. Values stored in columns having LONG RAW data type cannot be indexed. DATA DEFINITION COMMAND:- 1) CREATE TABLE:- This command is used to create the table(rows and columns) with headings. Syntax:- Create table <table name> (<column name1> <datatype> (<size>), <column name2><data type> (<size>)); Example:- SQL> Create table emp (emp_name char (10), desg varchar (5),address varchar (20)); Table created. 2) INSERT:- This command is used to insert the rows/data in the table. Syntax:- Insert into <table name> values(<expression1>, <expression2>);

11 Example:- SQL> Insert into emp values( ram, mgr, rajpura ); 1 row created. SQL> select * from emp; EMP_NAME DESG ADDRESS -------------------- ------------ -------------------- Ram mgr rajpura 3) ALTER:-This command is used to modify or make changes existing table. Syntax:- Alter table <table name> add (<new column name> <data type> (<size>)); Example:- SQL> alter table emp add (pin_code varchar(10)); Table altered. SQL> select * from emp; EMP_NAME DESG ADDRESS PIN_CODE -------------------- ------------ -------------------- ------------------- Ram mgr rajpura 4) DROP:-This command is used to delete the particular table. Syntax:- Drop table <table name>;

12 Example:- Drop table emp; Table dropped. 5) DELETE:- This command is used to delete data or row from particular table. Syntax:- Delete from <table name> where <condition>; Example:- SQL> delete from emp where address = rajpura; 1 row deleted. 6) UPDATE:- This command is used to change or modify values in the table. Syntax:- Update <table name> set <column name1> = <expression1>; Example:- SQL> update emp set pin_code =12345; 1 row updated. EMP_NAME DESG ADDRESS PIN_CODE -------------------- ------------ -------------------- ------------------- Ram mgr rajpura 12345