This action might not be possible to undo. Are you sure you want to continue?
Aim: Introduction about Database. What is Database?
A database consists of an organized collection of interrelated data.
What Is a DBMS?
• • • • Consists of two things- a Database and a set of programs. Database is a very large, integrated collection of data. The set of programs are used to Access and Process the database. So DBMS can be defined as the software package designed to store and Manage or process the database.
Why we use a DBMS?
• • • • • Data independence and efficient access. Reduced application development time. Data integrity and security. Uniform data administration. Concurrent access, recovery from crashes.
Major Components of a DBMS
1. 2. 3. 4. • • • • Data Definition Language Interpreter/ Compiler Data Manipulation Language Compiler Query processor Database Manager
Data Definition Language (DDL)
This language provides a set of commands which can be used to define what is the data in database. what is the relationship between various data elements what are the integrity constraints put on various data items needed to be satisfied etc..
Data Manipulation Language(DML)
• • • It is a language that enables users access or manipulate data from the database. This consists of very high level statements that are used to specify the operations to be performed on the database.
• It is the portion of DML that is used to access or retrieve the information from the database.
This is the software that takes care for execution of all the statements specified in DDL or DML. This software handles all the problems of a database and is responsible for providing all of the features claimed above like data consistency, non-redundant data, atomicity, concurrency control, easy access to data etc.
Types Of Users:
• • • • DBA: Person who designs the database and writes database schema in DDL based on the design Sophisticated Users: People who know DML commands and operate on database directly. Application Programmers: People who operate on the database through the application programs usually written in some high level computer language like C, Java, VB etc. Naïve Users: People who executes the application programs through APIs written specifically for their requirements. They are generally not aware of the computer technology e.g. tellers, agents, registrars, librarian etc.
Introduction to structured query language (SQL):
• Structured query language is a language that provide an interface to relational database system. SQL was developed be IBM in the 1970.
Features of SQL
• • • • SQL can be used by a range of users including those with little or no programming experience It is a non procedural language. It reduced the amount of time required for creating and maintaining systems It is an English-like language.
Rules for SQL
• • • • • • • SQL starts with a verb. Ex: SELECT statements. This verb may have additional adjective ,Ex: FROM Each verb is followed by number of clauses. Ex: FROM ,WHERE,HAVING A space separate clause. Ex: DROP TABLE EMP; A comma(,) separate parameter without a clause A ‘;’ is used to end SQL statement Statement may be split across lines but keywords may not Lexical units such as identifiers, operator name,literal are separate by one or more spaces or otherdelimiters will not be confused with the lexical units.
Practical – 2
Aim: To study about SQL syntax.
Create the tables described below: Table Name: CLIENT_MASTER Description: Used to store client information Column name Data types Size Defaults CLIENTNO Varchar2 6 NAME Varchar2 20 ADDRESS1 Varchar2 30 ADDRESS2 Varchar2 30 CITY Varchar2 15 PINCODE Number 8 STATE Varchar2 15 BALDUE Number 10,2 Table Name: PRODUCT_MASTER Description: Used to store porduct information Column name Data types Size Defaults PRODUCTNO Varchar2 6 DESCRIPTION Varchar2 15 PROFITPERCENT Number 4,2 UNITMEASURE Varchar2 10 QTYONHAND Number 8 REORDERLVL Number 8 SELLPRICE Number 8,2 COSTPRICE Number 8,2
Table Name: SALESMAN_MASTER Description: Used to store salesman information working for the company Defaults Attributes Column name Data types Size SALESMANNO Varchar2 6 SALESMANNAME Varchar2 20 ADDRESS1 Varchar2 30 ADDRESS2 Varchar2 30 CITY Varchar2 20 PINCODE Number 8 STATE Varchar2 20 SALAMT Number 8,2 TGTTOGET Number 6,2 YTDSALES Number 6,2 REMARKS Varchar2 60
Data for CLIENT_MASTER tables ClientNo C00001 C00002 C00003 C00004 C00005 C00006 Name Ivan Bayross Mamta Muzumdar Chhya Bankar Ashwin Joshi Hansel Colaco Deepak Sharma City Mumbai Madras Mumbai Bangalore Mumbai Mangalore Pincode 400054 780001 400057 560001 400060 560050 State Maharashtra Tamil Nadu Maharashtra Karnataka Maharashtra Karnataka BalDue 15000 0 5000 0 2000 0
Data for PRODUCT_MASTER tables Product No P00001 P0345 P06734 P07865 P07867 P07885 P07965 P07975 P08865 Description Profit Percen t 5 6 5 5 2 2.5 4 5 5 Unit Measur e Piece Piece Piece Piece Piece Piece Piece Piece Piece QtyOn Hand 200 150 100 100 150 80 100 70 75 ReorderL vl 50 50 20 20 50 30 40 30 30 SellPric e 350 500 600 750 850 700 350 300 450 CostPric e 250 350 450 500 550 450 250 175 300
T-Shirts Shirts Cottan Jeans Jeans Trousers Pull Overs Denim Shirts Lycra Tops Skirts
Data for SALESMAN_MASTER tables SalesmanNo S00001 S00002 S00003 S00004 SalesmanNo S00001 S00002 S00003 S00004 Name Aman Omkar Raj Ashish SalAmt 3000 3000 3000 3000 Address1 A/14 65 P-7 A/5 TgtToGet 100 200 200 200 Address2 Worli Nairman Bandra Juhu YtdSales 50 100 100 150 City Mumbai Mumbai Mumbai Mumbai Remarks Good Good Good Good PinCode 400002 400001 400032 400044 State Maharashtra Maharashtra Maharashtra Maharashtra
size. Rules for Creating a Table • • • • • A name can have maximum up to 30 character. <ColumnName2> <DataType>(<size>)). Syntax Ø INSERT INTO <tablename> (<columnname1> <columnname2>) VALUES (<expression1> . For Ex: create. < expression2>).a-z and number from 0-9 are allowed A name should begin with an alphabet The use of the special character like_ is allowed and also recommanded. SQL reserved words not allowed .The CREATE TABLE Command • The CREATE TABLE command defined each column of the table uniquely. Each column has a minimum of three attribute a name. and so on. Syntax Ø CREATE TABLE <TableName> (<ColumnName1> <DataType>(<size>). 1) Create a table client_master. datatype. select . Inserting Data Into Tables Load the values passed into the column specified. Alphabets from A-Z . Query: Output: .
Query: Output: 3) Create a table salesman_master. Query: Output: .2) Create a table client_master.
Query: .1) Insert the data into the client_master. Query: Output: 2) Insert the data into the client_master.
Output: 3) Insert the data into table salesman_master. Query: Output: .
Retrieve all rows and all columns Ø SELECT <ColumnName 1> To <ColumnName N> FROM TableName.<ColumnName 2> FROM <TableName>. Query: Output: b) Retrieve the entire contents of the Client_Master table. Selected rows and selected columns Ø SELECT <ColumnName 1>. Query: . a) Find out the names of all the clients. Next operation would be to view data into the table. <ColumnName 2> FROM <TableName>. To retrieve data from the table. Exercise on retrieving record from a table. Selected rows and all columns Ø SELECT * FROM <TableName> WHERE <Condition>.<ColumnName 2> FROM <TableName> WHERE <Condition>. For that SELECT SQL verb is used. Selected all rows and columns Ø SELECT <ColumnName 1>.Viewing data in the table • • Once data has been inserted into a table. Eliminating Duplicate rows when using a select statement Ø SELECT DISTINCT <ColumnName 1>.
city. Query: Output: d) List the various product available from the Product_Master table. and the sate of all the clients . Query: Output: .Output: c) Retrieve the list of names.
<ColumnName2> = <Expression 2>. Query: Output: Update the content of table. Update Records Conditionally Ø Update <TableName> set <ColumnName1> = <Expression1>.e) List all the client who are located in Mumbai. Query: Output: f) Find the names of salesman who have a salary equal to Rs.<ColumnName2> = <Expression 2> where <condition>. Ø Update <TableName> set <ColumnName1> = <Expression1>.3000. .
950. Query: Output: c) Change the cost price of ‘Trousers’ to Rs. Query: Output: b) Change the Baldau of clientno ‘C0001’ to Rs. 1000. Query: Output: .00.Exercise on updating records in a table a) Change the city of clientno ‘C00001’ to ‘Bangalore’.
Query: Output: b) Delete all product from Product_master where the quantity on hand is equal to 100.3500. a) Delete all salesman from the Salesman_master whose salaries are equal to Rs.d) Change the city of the salesman to Pune. Ø DELETE FROM <tablename> where <columnname> = <expression> Exercise on deleting record on the table. Query: Output: . Query: Output: Delete record on condition.
Query: Output: . Exercise on the altering the structure a) Add new column called ‘Telephone’ of datatype ‘number’ and size=’10’ to the Client_Master table. Dropping a column from a table Ø ALTER TABLE <TableName> DROP COLUMN <ColumnName> Modifying Existing Columns Ø ALTER TABLE <tablename> MODIFY(<ColumnName> <NewDataType>(<NewSize>)). Query: Output: Adding new columns Ø ALTER TABLE <TableName> (<NewColumnName> <DataType>(<size>).. <NewColumnName> <DataType>(<size>)..).c) Delete from client_master where the column state holds the values ‘Tamin Nadu’.
Query: .b) Change the size of SellPrice column in Porduct_Master to 10. Query: Output: Destroy the table with its data Ø DROP TABLE <TableName> Exercise on deleting the table structure along with the data c) Destory the name of the Salesman_Master along with its data.2. Query: Output: Rename the table Ø RENAME <TableName> To <NewTableName> Exercise on renaming the table a) Change the name of the Salesman_Master table to sman_mast.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.