Вы находитесь на странице: 1из 52

1. B.NAGARAJU 2. SRIDHAR REDDY 3. P.SHAILAJA 4. PADMAVATHI 5.

QURRATHUL AIN HAROON

Week 1: E-R Model


E-R Model describes data as entities, relationships and attributes .The ER-Model is important preliminary for its role in database design. ER Model is usually shown pictorially using entity relationship diagrams. Some basic concepts of E-R model are described below.

Entity: The object in the ER Model represents as an entity. Entity is the thing in the real world with an independent existence. In ER modeling an entity is shown as a rectangle and name in it. e.g. Entity_Name

E-R Diagram: Shows the entities and relations pictorially. That is how the entities are related among themselves.

e.g.

Entity_1

Relates

Entity_2

Attributes: The properties that characterize an entity set are called its attributes. An attribute is referred to by the terms data items, data element, data field item. Ex: attributes for bus entity and ticket entity.

Types of attributes: There are different types of attributes Domain Attribute: The set of possible values for an attribute is called the domain of the attribute.
Divorced Marital status Single

Married

Widowed

Key Attribute: The attribute (or combination of attributes) that is unique for every entity instance. Eg: The account number of account The employee id of an employee Simple Attribute: The attribute which cant be broken-down into small components.

AGE

Composite Attribute: The attribute which can be split into components.


Day

Date

Month

Year

Single valued Attribute: The attribute can take on only a single value for each entity instance.

Phno

Multi-valued Attribute: An attribute that may take more than one value for a given entity. It is represented with double ellipse.

Addr Pincode

Hno Street City

Stored Attribute: Attribute that need to be stored permanently. Eg: Name of employee

Derived Attribute: Attribute that can be calculated based on other attributes. It is represented with dotted lines.

EMP

Joining Date

Current Date

Keys:

Candidate Key: It can be defined as an attribute or combination of attributes that identifies


the record uniquely but none of its proper subsets can identify the record uniquely. Primary Key: A candidate key that is used by the database designer for unique identification of each row in a table is known as primary key. A primary key consists of one or more attributes of the table.

Partial key: A weak entity type normally has a partial key which is the set of attributes that can uniquely identify weak entity that are related to the same owner entity.

Super Key: This can be defined as the combination of all keys.

Foreign key: A foreign key (FK) is an attribute or combination of attributes that is used to
establish and enforce a link between the data in two tables. In a foreign key reference, a link is created between two tables when the column or columns that hold the primary key value for one table are referenced by the column or columns in another table. This column becomes a foreign key in the second table.

Composite key: Sometimes it requires more than one attribute to uniquely identify an entity. A
primary key that made up of more than one attribute is known as a composite key. For our database we identify entities as below. o o o o o Bus: Primary key: BusNo and ServiceNo Passenger: Primary key: PassengerId, Foreign key: TicketId Ticket: Primary key: TicketId, Foreign key: BusNo Reservation Cancellation

Week 2: Concept Design with E-R Model


Relationship: A relationship type between two entity types defines the set of all associations between these entity types Each instance of the relationship between members of these entity types is called a relationship instance. e.g.Customer creates an acount in bank, here creating account is a relation between Customer and Bank entity. Entity diagrams with Attributes:

Customer Entity:

Account Entity:

Bank Entity:

Administration Entity:

Deposit Entity:

Withdraw Entity:

Transfer Entity:

Cardinalities: Cardinality relationships can have different connectivity A ratio, such as 1:1, 1: N, M: 1, and M: N, gives a cardinality constraint or numeric restriction on the possible relationships. One-to-one (1:1): relationship from entity type S to entity type T is one in which an entity from S is related to at most one entity from T and vice versa. One-to-many (1: N): relationship from entity type S to entity type T is one in which two or more entities from T can be related to an entity from S.

Many-to- One (M: 1): relationship from entity type S to entity type T is one in which an entity from S can be related to two or more entities from T. Many-to-many (M:N): relationship from entity type S to entity type T is one in which an entity from S can be related to two or more entities from T, and an entity from T can be related to two or more entities from

E R Diagrams :
Create account

Close account

Check Balance

Deposit

Withdraw

Transfer

Management

Bank Management System

Types of Entities: There are 2 types of entities. Strong Entity: A Strong Entity is one that exists on its own, independent of other entities. An entity set that has primary key is termed as strong entity set. Weak Entity: A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner, many weak entities).Weak entity set must have total participation in this identifying relationship set. Types of Relationships: Aggregation: Aggregation refers to an abstraction in which a relationship between objects is regarded as a higher-level object. Generalization: It is a relationship that exists between a high level entity set and one or more lower level entity set.

Specialization: Is the process of defining a set of subclasses of a super class .The set of subclasses is based upon some distinguishing characteristics of the entities in the super class. Super class/subclass relationships and specialization can be diagrammatically represented in ER diagrams.

Week 3: Relational Model


Relation can be defined as a set of tuples. Here all tuples in a relation must be distinct, that is no two tuple can have the same combination of values for all their attributes. Schema is the basic design of a relation i.e. nothing but a table design. In our database the schema of tables would be as follows: Customer table schema: cust_id cust_name Age DOB Gender Ph_no Address

Customer

cust_id: number(11) PRIMARY KEY cust_name: varcharchar2(20) Age : number(2) Gender : varchar2(6) DOB : date Ph_no : number(10) Address : varchar2(50) Account table schema: Account_no Account_type Date_of_creating_account Date_of_closing_account

Account Accoun_ no: varcha2(10) PRIMARY KEY Account_type: varchar2(10) Date_o_creating_account : date Date_of_closing_account : date Bank table schema: IFSC Bank_name Branch Ph_no Address

Bank IFSC : number(10) PRIMARY KEY Bank_ name : varchar2(20)

Branch : varchar2(20) Ph_no: number(10) Address: varchar2(30)


Administration Schema:

Emp_id

Emp_name

Designation

Department

Administration Emp_id : number(10) PRIMARY KEY Emp_name: varchar2(25)

Designation: varchar2(15) Department: varchar2(15) Deposit Schema:

Account_no

Cust_id

Cust_name

Date_of_deposit Amount

Deposit Account_no : varchar(11) foreign key(Account_no) reference to Account(Account_no) Cust_id number(11) foreign key(cust_id) reference to Customer(Cust_id) Date_of_deposit : date, Cust_name : varchar2(30) Amount: number(11)

Withdraw schema:

Account_no

Cust_id

Cust_name

Date_of_withdraw

Amount

Withdraw Account_no : varchar(11) foreign key(Account_no) reference to Account(Account_no) Cust_id number(11) foreign key(cust_id) reference to Customer(Cust_id) Cust_name : varchar2(20) Date_of_withdraw :date Accoun_ no : number(11) references customer(cust_id) Amount: number(11) Transfer schema: TO FROM _ACCOUNT _ACCOUT_NO Amount _NO

Cust_name Transfer

Date_of_transfer

Cust_name : varchar2(20)

Date_of_transfer :date To account:number(10) From account:number(11)

Week4: Normalization
Database normalization is a technique for designing relational database tables to minimize duplication of information and, in doing so , to safeguard the database against certain types of logical or structural problems namely data anomalies. Normal Forms:

1st Normal Form: 1NF requires that the values in each column of a table are atomic. By atomic we mean that there are no sets of values within a column. So the relation gets normalized under the 1ST normal form as below by splitting the record into two records. Cust_id cust_name Age gender DOB Phno ADDRESS Preetam 1010054211 Sreeram 1010054212 Shankar 1010054213 Ashutosh 1010054214 Aruna 1010054215 Anvesh 1010054216 Saidatta 1010054217 31 M 03-12-1982 8066952326 20 M 23-01-1991 8011478532 20 F 04-05-1991 8011478531 31 M 05-08-1980 9866324324 32 M 23-07-1979 9440440440 27 M 02-12-1984 30 M 03-04-1981 9949887766 9873838272 9440565656 #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #4-12/1/2, Malakpet, Hyderabad #1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad #2-45/6/2, Lungarhouse, Hyderabad

Normalized Relation: Cust_id cust_name Age gender DOB PHN_N0 ADDRESS

03-04-1981 1010054211 Preetam 30 M 03-04-1981 1010054211 Preetam 30 M

9949887766

#1-345, Narayanaguda, Hyderabad #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad Malakpet,

9873838272

1010054212

Sreeram

27

02-12-1984 23-07-1979

9440565656

1010054213

Shankar Ashutosh

32

M 05-08-1980

9440440440 #4-12/1/2, Hyderabad 9866324324

1010054214 Aruna 1010054215 Anvesh 1010054216 Saidatta 1010054217

31

M 23-01-1991 8011478531

#1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad #2-89/A/1, Santoshnar, Hyderabad

20

F 23-01-1991 8011478532

20

M 03-12-1982 8066952326

29

2nd Normal Form: where the 1NF deals with atomicity of data, the 2NF deals with relationships between composite key columns and non-key columns. To achieve 2NF the tables should be in 1NF. The 2NF any non-key columns must depend on the entire primary key. In case of a composite primary key, this means that non-key column cant depend on only part of the composite key. That is no Partial Functional Dependencies shoud exist. In our entities Deposit entity is having the keys with the combination of account_no and cust_id . But there exists the following partial functional dependency: ACCOUNT_NO CUST_ID,CUST_NAME So in order to avoid this we normalize the Deposit table as below.

ACCOUNT_NO 1234A21012 123J90187K 123FGT5678 1234M4567D

Cust_id 1010054211 1010054212 1010054213 1010054214

Cust_name Preetam Sreeram Shankar Ashutosh

Date of deposit 12-09-2010 09-12-2010 22-08-2010 23-04-2010

Amount 120000 130000 3000 40000

Normalized Relations: ACCOUNT_NO CUST_ID,CUST_NAME

Account_no 1234A21012 123J90187K 123FGT5678

Cust_id 1010054211 1010054212 1010054213

Cust_name Preetam Sreeram Shankar Ashutosh

1234M4567D 1010054214

ACCOUNT_NO DATE OF DEPOSIT,AMOUNT ACCOUNT_NO DATE OF DEPOSIT 1234A21012 123J90187K 123FGT5678 1234M4567D 12-09-2010 09-12-2010 22-08-2010 23-04-2010 120000 130000 3000 40000 AMOUNT

3rd Normal Form: 3NF requires that all columns depend directly on the primary key. Tables violate the third normal form when one column depends an another column, which in turn depends on the primary key(transitive dependency). One way to identify transitive dependency is to look at your tables and see if any columns would require updating if another column in the table was updated. If such a column exists, it probably violates 3NF. In our entities CUSTOMER entity faces the Transitive Dependency problem.The following transitive dependencies exist: CUST_ID DOB DOB AGE To eliminate this problem the relation is normalized as follows. Cust_id cust_name Age gender DOB 03-04-1981 1010054211 Preetam 30 M PHN_N0 9873838272 ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad

1010054212

Sreeram

27

02-12-1984 23-07-1979

9440565656

1010054213

Shankar Ashutosh

32

M 05-08-1980

9440440440 #4-12/1/2,Malakpet, Hyderabad 9866324324 #1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad #2-89/A/1, Santoshnar, Hyderabad

1010054214 Aruna 1010054215 Anvesh 1010054216 Saidatta 1010054217

31

M 23-01-1991 8011478531

20

F 23-01-1991 8011478532

20

M 03-12-1982 8066952326

29

CUST_ID DOB Cust_id cust_name gender DOB 03-04-1981 1010054211 Preetam M PHN_N0 9873838272 ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #412/1/2,Malakpet, Hyderabad #1-234, Chikkadpally, Hyderabad

1010054212

Sreeram

02-12-1984 23-07-1979

9440565656

9440440440

1010054213

Shankar Ashutosh

M 05-08-1980 M 9866324324

1010054214 DOB AGE Cust_id cust_name

gender

Age

PHN_N0 9873838272

ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #412/1/2,Malakpet, Hyderabad #1-234, Chikkadpally,

1010054211

Preetam

30

9440565656 1010054212 Sreeram M 27 9440440440 1010054213 1010054214 Shankar Ashutosh M M 32 31 9866324324

Hyderabad

Boyce Codd Normal Form: Takes care of candidate keys. A relation in a Boyce Codd normal form iff every determinant in the relation is a candidate key. That is this normal form eliminates the overlapping candidate keys.

Week 5: Installation of MySQL


Download MySQL software from the web site http://www.soft82.com/get/download/mysqlworkbench Save the file and then run the set up after downloading. Before running Mysql workbench we have to install .net framework of version 2.0 (or) higher.Now we have to download the .net framework from the web site: http://www.brothersoft.com/net.framework-download-112623.html Before installing the .net frame work we have to download the Windows Installer 3.1 to support the .net frame work from the web site: http://www.microsoft.com/downloads/

Windows Installer Installation: After downloading the Windows Installer 3.1 software run the set up.

Start the set up wizard and click NEXT. Next click on the LICENSE agreement to ACCEPT and again click NEXT. Now updating the system process starts. After installing the Windows Installer 3.1 software click on FINISH.

.NET Framework Installation: Now start the installation process of .net frame work to install Mysql Work Bench. Start the set up wizard. Next ACCEPT the LICENCE AGREEMENT and click INSTALL. Now the DOWNLOAD and INSTALLATION process starts. Before INSTALLATION, it first DOWNLOADS the components of .net frame work from internet and then starts the INSTALLATION process. After completing the INSTALLATION process click on EXIT and the setup is completed.

MySQL Work Bench Installation: Run the setup. It will show setup wizard like the following window.

Now click on NEXT to start the INSTALLATION process. Now select the Setup Type. Complete Custom

Click on COMPLETE to install all program feature and click NEXT. Now click on INSTALL to start the installation process. Now the INSTALLATION process starts. Now click on FINISH to complete the setup wizard. The overall INSTALLATION process has been completed. And we can perform QUERIES by using MySQL Work Bench. We are going to execute the queries by using MySQL server.

MySQL Server Installation: Step 1: Download mysql server essential from the website www.mysql.com/downloads and save the .exe file.

Steps 2&3: Double click on the mysql.exe file to start installation.

Steps 4&5:

Steps: 6&7

Steps 8&9:

Steps: 10&11

Step: 12&13

Steps: 14&15

Steps: 16&17

Steps: 18&19

DDL Commands
Data Definition Language commands are used for the basic operations like creating, deleting etc..of database tables. There are many DDL Commands some of them are described below. Create: It is used to create the tables in the database. On a specific database a new table is created using create command. Syntax: CREATE TABLE TABLE_NAME(ATTRIBUTE_LIST); e.g. CREATE TABLE CUSTOMER (CUST_ID NUMBER(11) PRIMARY KEY, CUST_NAME VARCHAR2(20), AGE NUMBER(2) ,DOB DATE, GENDER VARCHAR2(1), PH_NO NUMBER(10),ADDRESS VARCHAR2(40));

Above example creates a table called CUSTOMER. With DESC command we can view the basic table scheme. DESC CUSTOMER; Above command shows the table design as follows. Field CUST_ID CUST_NAME AGE DOB GENDER PH_NO ADDRESS Type NUMBER(11) Null NO Key PRI Not Null Not Null Not Null Not Null Not Null Not Null Default Extra

VARCHAR2(20) YES NUMBER(2) DATE VARCHAR2(2) NUMBER(10) YES YES YES YES

VARCHAR2(40) YES

* Lets consider our DB is having a table called DEMO. Rename: It is used to change the table name in the database. Syntax: RENAME TABLE OLD_TABLE_NAME TO NEW_TABLE_NAME; e.g. RENAME TABLE DEMO TO DEMO1;

Alter: It is used to add or remove the columns/fields from existing table. Syntax: ALTER TABLE TABLE_NAME ADD/REMOVE FIELD_NAME; e.g. ALTER TABLE DEMO1 ADD EXTRA_FIELD CHAR(10); Above example adds one extra field EXTRA_FIELD to the DEMO1 table. Truncate: It is used to delete only the records of the table in the database Syntax: TRUNCATE TABLE TABLE_NAME; e.g. TRUNCATE TABLE DEMO1; Above command deletes all records of DEMO1 table. Drop: It is used to delete the entire table from the database. Syntax: DROP TABLE TABLE_NAME; e.g. DROP TABLE DEMO1;

Above table deletes DEMO1 table completely from database.

Week 6: DML Commands


Data Manipulation Language commands are used for access/ manage the data items in database table. Some of the DML commamds are described below. Insert: It is used to insert the data items in to the created tables in the database. Syntax: INSERT INTO TABLE_NAME VALUES(values);

e.g.

INSERT INTO CUSTOMER VALUES (1010054211,Preetham,30,m,03-01-1981,

9949887766, #1-345, Narayanaguda, Hyderabad); INSERT INTO CUSTOMER VALUES (1010054212,Sreeram,27,m,02-12-1984, 9440565656, #3-11/A, Bowenpally, Hyderabad); Above 2 queries insert the values in CUSTOMER table. Select: It is used to select/retrieve the data from the tables in the database. Syntax: SELECT FIELD(S) FROM TABLE_NAME; e.g. SELECT * FROM CUSTOMER; Above command retrieves all the records of BUS table and shows like the follow. Here * indicates all fields values. into two records.

CUST_ID

CUST_NA ME Preetam

AG E 30

GEND ER M

DOB 03-04-1981

PHNO 9949887766

ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #4-12/1/2, Malakpet, Hyderabad #1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad

1010054211 Sreeram 1010054212 Shankar 1010054213 Ashutosh 1010054214 Aruna 1010054215 Anvesh 1010054216 20 M 23-01-1991 8011478532 20 F 04-05-1991 8011478531 31 M 05-08-1980 9866324324 32 M 23-07-1979 9440440440 27 M 02-12-1984 9440565656

Saidatta 1010054217

31

03-12-1982

8066952326

#2-45/6/2, Lungarhouse, Hyderabad

Update: It is used to update the existing data within a table in the database. Syntax: UPDATE TABLE_NAME SET FIELD=VALUE WHERE CONDITION; e.g. UPDATE CUSTOMER SET CUST_NAME=nagaraju WHERE CUST_ID=1010054211; Above query sets name nagaraju in CUST_NAME field in the 1010054211 CUST_ID record in CUSTOMER table. If we select the records from BUS table, it will show table as follows.

CUST_ID

CUST_NA ME Nagaraju

AG E 30

GEND ER M

DOB 03-04-1981

PHNO 9949887766

ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #4-12/1/2, Malakpet, Hyderabad #1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad #2-45/6/2, Lungarhouse, Hyderabad

1010054211 Sreeram 1010054212 Shankar 1010054213 Ashutosh 1010054214 Aruna 1010054215 Anvesh 1010054216 Saidatta 1010054217 31 M 03-12-1982 8066952326 20 M 23-01-1991 8011478532 20 F 04-05-1991 8011478531 31 M 05-08-1980 9866324324 32 M 23-07-1979 9440440440 27 M 02-12-1984 9440565656

Delete: It is used to delete the records from the tables and the space will remain same in the table with empty space.

Syntax: DELETE TABLE_NAME WHERE CONDITION; e.g. DELETE CUSTOMER WHERE CUST_ID=1010054217; Above query will delete record related to the customer id is 1010054217 from CUSTOMER table.

CUST_ID

CUST_NA ME Nagaraju

AG E 30

GEND ER M

DOB 03-04-1981

PHNO 9949887766

ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #4-12/1/2, Malakpet, Hyderabad #1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad

1010054211 Sreeram 1010054212 Shankar 1010054213 Ashutosh 1010054214 Aruna 1010054215 Anvesh 1010054216 20 M 23-01-1991 8011478532 20 F 04-05-1991 8011478531 31 M 05-08-1980 9866324324 32 M 23-07-1979 9440440440 27 M 02-12-1984 9440565656

DataBase Tables creation


Account Table

MySQL>

CREATE

TABLE

ACCOUNT

(ACCOUNT_NO varchar2(10), IFSC

REFERENCES REFERENCES

CUSTOMER(CUST_ID),

ACCOUNT_TYPE

BANK(IFSC), DATE_OF_CREATING_ACCOUNT date, DATE_OF_DELETING_ACCOUNT date, AMOUNT number(11)); MySQL> INSERT INTO ACCOUNT VALUES (1010054211, savings, 23239, 11-jan1998, NULL,15000); MySQL> INSERT INTO ACCOUNT VALUES (1010054212, savings, 23239, 11-jun2003, NULL,14000); MySQL> INSERT INTO ACCOUNT VALUES (1010054213, savings, 11007 30-jan2008, NULL,23000);

MySQL> SELECT * FROM ACCOUNT;

ACCOUNT_NO

ACCOUNT _TYPE

IFSC

DATE_OF_CREA DATE_OF_DE TING_ACCOUN T LETING_ACC OUNT NULL NULL NULL NULL NULL NULL

AMOUNT

1234A21012 123J90187K 123FGT5678 1234M4567D 1234GH56710 1230978GFW

Savings Joint Savings Current Savings Savings

23239 23239 11007 11557 45379 11007

11-jan-1998 11-jun-2003 30-jan-2008 28-apr-2003 17-aug-2009 15-sep-2006

15,000 14,000 23,000 11,000 29,000 15,000

Bank Table MySQL> CREATE TABLE BANK(BANK_ NAME varchar2(20), IFSC number(5) PRIMARYKEY, BRANCH varchar2(20), ADDRESS varchar2(30),

PH_NO number(10)); MySQL> INSERT INTO BANK VALUES(SBI,11007,Dilshuknagar,DSNR,9441808080); MySQL> INSERT INTO BANK VALUES(SBI,11667,Gaddiannaram,Gaddiannaram , 9440566022); MySQL> INSERT INTO BANK VALUES(SBI,23239,BNReddy Nagar,BNReddy Nagar, 9490997654); MySQL> INSERT INTO BANK VALUES(SBI,45379,Uppal,Uppal X roads,9030547823);

MySQL> SELECT * FROM BANK;

BANK_NAME SBI SBI SBI SBI

IFSC 11007 11557 23239 45379

BRANCH Dilshuknagar Gaddiannaram BNReddy Nagar Uppal

ADDRESS DSNR Gaddiannaram BNReddyNagar Uppal X roads

PH_NO 9441808080 9440566022 9490997654 9030547823

ADMINISTRATION TABLE EMP_ID 10023 10052 10072 10084 EMP_NAME Nagaraju Raghava Preetham Nagarjuna DESIGNATION MANAGER Asst MANAGER CASHIER DEPARTMENT

DEPOSITE TABLE

ACCOUNT_NO 1234A21012 123J90187K 123FGT5678 1234M4567D

Cust_id 1010054211 1010054212 1010054213 1010054214

Cust_name Preetam Sreeram Shankar Ashutosh

Date of deposit 12-09-2010 09-12-2010 22-08-2010 23-04-2010

Amount 120000 130000 3000 40000

WITHDRAW TABLE

ACCOUNT_NO 1234A21012 123J90187K 123FGT5678 1234M4567D

Cust_id 1010054211 1010054212 1010054213 1010054214

Cust_name Preetam Sreeram Shankar Ashutosh

Date of withdraw 12-09-2010 09-12-2010 22-08-2010 23-04-2010

Amount 120000 130000 3000 40000

TRANSFER TABLE

CUST_NAME

TO_ACCOUNT_ NO

FROM_ACCOUNT _NO 1010054215 1010054213 1010054211 1010054213

DATE_OF_TR ANSFER 18-AUG-2009 31-DEC-2009 27-NOV-2007 19-JUL-2007

AMOUNT

Nagaraju Aruna Shankar Anvesh

1010054211 1010054215 1010054213 1010054216

5,000 4,000 8,000 6,000

Week 7: Querying

Practicing the some queries


1. Display CUSTOMER NAME, CUSTOMER ID of all customers. MySQL> SELECT CUST_ID,CUST_NAME FROM CUSTOMER;

CUSTOMER_ID 1010054211 1010054212 1010054213 1010054214 1010054215 1010054216

CUST_NAME Nagaraju Sreeram Shankar Ashutosh Aruna Anvesh

2. Display all the names of male customers.

MySQL> SELECT CUST_NAME CUSTOMER WHERE GENDER=M; CUST_NAME Nagaraju Sreeram Shankar Ashutosh Anvesh

3. Display names and address of all the customers. MySQL> SELECT CUST_NAME,ADDRESS FROM CUSTOMER;

CUST_NAME Nagaraju Sreeram Shankar Ashutosh Aruna Anvesh

ADDRESS #1-345, Narayanaguda, Hyderabad #3-11/A, Bowenpally, Hyderabad #4-12/1/2, Malakpet, Hyderabad #1-234, Chikkadpally, Hyderabad #1-234, Chikkadpally, Hyderabad #2-89/A/1, Santoshnar, Hyderabad

4. Display the IFSC, bank name, branch details for all banks. MySQL> SELECT BANK_NAME,IFSC,BRANCH FROM BANK;

BANK_NAME SBI SBI SBI SBI

IFSC 11007 11557 23239 45379

BRANCH Dilshuknagar Gaddiannaram BNReddy Nagar Uppal

5. Display the account number of custmers whose names start with a and end with h. MySQL> SELECT CUST_ID,CUST_NAME FORM CUSTOMER WHERE NAME LIKE A%H;

CUST_ID 1010054214 1010054216

CUST_NAME Ashuthosh Anvesh

6 . Find names of customers whose age is between 30 and 45. MySQL> SELECT CUST_NAME FROM CUSTMER WHERE AGE BETWEEN 30 AND 45; CUST_NAME Nagaraju Ashuthosh Shankar

7. Display all customer names whose name starts with a. MySQL>SELECT CUST_NAME FROM CUSTOMER WHERE NAME LIKEA%; CUST_NAME

Ashutosh Aruna Anvesh

8. Display sorted list of customer names. MySQL> SELECT CUST_NAME FROM CUSTOMER ORDER BY CUST_NAME;

CUST_NAME Anvesh Aruna Ashutosh Nagaraju Preetam Shankar Sreeram

Week 8 and 9: Querying (Continued)


1. Write a query to display the customer name ,customer id, IFSC MySQL>SELECT C.CUST_ID,C.CUST_NAME,A.IFSC FROM ACCOUNT A, CUSTOMER C WHERE C.CUST_ID=A.ACCOUNT_NO;

CUSTOMER_ID 1010054211 1010054212

CUST_NAME Nagaraju Sreeram

IFSC 23239 23239

1010054213 1010054214 1010054215 1010054216

Shankar Ashutosh Aruna Anvesh

11007 11557 45379 11007

2. Write a query to display account number where amount is less than 20,000. MySQL> SELECT ACCOUNT_NO FROM ACCOUNT WHERE AMOUNT <20000;

ACCOUNT_NO 1010054211 1010054212 1010054214 10100542166

3. Display the number of accounts in the bank IFSC is 11007. MySQL> SELECT COUNT(ACCOUNT_NO) FROM ACCOUNT HAVING IFSC=11007;

COUNT(ACCOUNT_NO) 2

4. Display the account number, name, amount of all customers. MySQL>SELECT C.CUST_ID ACCOUNT_NO,C.CUST_NAME NAME,A.AMOUNT FROM CUSTOMER C, ACCOUNT A WHERE A.ACCOUNT_NO=C.CUST_ID;

ACCOUNT_NO 1010054211

NAME Nagaraju

AMOUNT 15,000

1010054212 1010054213 1010054214 1010054215 1010054216

Sreeram Shankar Ashutosh Aruna Anvesh

14,000 23,000 11,000 29,000 15,000

5. Write a query to display the account numbers and IFSC where brach name is dilshuknagar. MySQL>SELECT A.ACCOUNT_NO, A.IFSC FROM ACCOUNT A, BANK B WHERE A.IFSC=B.IFSC AND B.BRANCH=Dilshuknagar;

ACCOUNT_NO 1010015F413 10100DS54216

IFSC 11007 11007

Вам также может понравиться