SlideShare una empresa de Scribd logo
1 de 37
Database
What is Database ?


• Database is a collection of data in an
  organized way so that we can update, modify
  data present in database easily.
• Data storage in database is permanent.
• Eg: Oracle, MySQL, MS-Access, DB2, Sybase
How to store data in database?


• Data will stored in “Tables” in database in the
  form of “Records”.
• Table is a collection of relational data in 2D i.e
  in the form of rows and columns.
What is SQL ?


• SQL – Structure Query Language
• It is language used to access and modify the data
  stored in database.
• It uses statements to access the database.
• SQL Statements can be divided into two types:
   DML
   DDL
DDL(Data Definition Language)


• These statements are used for creation or
  deletion of database.
• The commands present in DDL are:
   Create
   Alter
   Drop
Create

• This command is used to create table or
  database.

• create database;//to create database

• create table table_name(column1_name
  datatype,column2_name datatype); // to create
  table
Alter

• This command is used to rename a table or column name of an
  existing table.

• It can also be used to modify, add, drop a column/field present in
  an existing table.

• alter table table_name rename new_table_name; //to rename
  table

• alter table table_name rename column old_column_name to
  new_column_name; //to rename column
Alter

• alter table table_name add column_name datatype;
  //to add a column to table

• alter table table_name modify column_name
  new_datatype; //to modify datatype of column of a
  table

• alter table table_name drop column column_name;
  //to drop a column of a table
Drop


• This command is used to remove an
  object(value).
• We can not get the table or values in it once
  the table is dropped.
• drop table table_name; //to drop a table
DML(Data Manipulation Language)


• These statements are used for managing the
  data in database.
• The commands present in DDL are:
   Insert
   Update
   Delete
   Select
Insert

• This command is used to enter the records
  into the table.

• insert into table_name values(‘value_col_1’,
  ‘value_col_2’); //to insert values into table
Update

• This command is used to update the value of a record
  or column of a table.
• We use condition to know where the updation is to be
  made.

• update table set column_name=“value” where
  some_column_name = “value_of_some_column”;
  //to update the column where it satisfies condition
Delete


• This command is used to delete the records (one or
  many) from a table by specifying some condition
  where to delete the record.

• delete from table_name where column_name =
  “value”;
 //to delete record where it satisfies given condition
select

• Select command is used to retrieve the records from
  the table.

• select column1_name, column2_name,…………. from
  table_name; //to select the specific columns from
  table

• select * from table_name; // to retrieve all records
  present in table
Integrity Constraints


•   Not Null
•   Unique
•   Primary Key
•   Foreign Key
•   Check
Not Null

• It is a constraint that ensures that every row is
  filled with some value for the column which has
  been specified as “not null”.

• create table table_name
  (column1_name datatype NOT NULL,
  column2_name datatype );
Unique

• It is a constraint used for column of a table so
  that rows of that column should be unique.
• It allows null value also.

• create table table_name(
  column1_name datatype UNIQUE,
  column2_name datatype);
Primary Key

• It is a constraint used for a column of a table
  so that we can identify a row in a table
  uniquely.
• create table table_name(
• column1_name datatype PRIMARY KEY,
• column2_name datatype);
Foreign key

• It is a constraint used to establish a relationship between
  two columns in the same or different tables.

• For a column to be defined as a Foreign Key, it should be a
  defined as a Primary Key in the table which it is referring.

• One or more columns can be defined as Foreign key.
• This constraint identifies any column referencing the
  PRIMARY KEY in another table.
SQL clauses


  •   select   • order by
  •   from     • group by
  •   where    • having
  •   update
Order by


• This clause is used the values of a column in
  ascending or descending order.
• select empname from emp1
  order by empname;
Group by


• This clause is used to collect data across
  multiple records and group results by one or
  more columns.
• select department from Student
  where subject1> 20
  group by department;
Having


• This clause is used in combination with sql group
  by clause.
• It is used to filter the records that a sql group by
  returns.
• select max(subject1) from Student
  group by department
  having min(subject1)>20;
Basic Functions

• COUNT() – to count the number of records satisfy
              condition.
• MAX()- to find the maximum value of a column of all
          the records present in table.
• MIN()- to find the minimum value of a column of
         all the records present in table.
• AVG()- to find the average value of a column of
         all the records present in table.
• SUM()- to find the sum of all the values of a column
          in a table.
Basic Functions

• AVG()- to find the average value of a column
         of all the records present in table.
• SUM()- to find the sum of all the values of a
          column in a table.
• Distinct() - to find the distinct record of a table
Joins

• Join is used to retrieve data from two or more
  database tables.
• Joins are of four types:
 Cross join- This join returns the combination of
  each row of the first table with every column of
  second table.
 Inner join-This join will return the rows from both
  the tables when it satisfies the given condition.
Joins

 Left Outer join –suppose if we have two tables. One on
  the left and the other on right side.

      When left outer join is applied on these two tables it
  returns all records of the left side table even if no
  matching rows are found in right side table

 Right Outer join- it is converse of left outer join. It
  returns all the rows of the right side table even if no
  matching rows are found in left side table.
JDBC
JDBC


• JDBC-Java Database Connectivity.
• JDBC is an API that helps us to connect our
  java program to the database and do the
  manipulation of the data through java
  program.
How to write a program in jdbc?


•   Register the Driver
•   Connecting to database
•   Create SQL statement in java
•   Execute SQL statements
•   Retrieve Result
•   Close Connection
JDBC program
public class JDBCProgram{
public static void main(String[] args) {
try {
        Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);//REGISTERING DATABASE
        Connection con = DriverManager.getConnection("jdbc:odbc:dsn", "",""); //CONNECTING DATABASE
        Statement st=con.createStatement();//CREATE STATEMENT
        st.execute("create table Employee(empid integer, empname varchar(50))");//EXECUTING STATEMENT
        st.close();// CLOSING STATEMENT
        con.close();//CLOSING CONNECTION
    }
catch (Exception err) {
      System.out.println( "Error: " + err );
      }
}
}
How to insert values into table using jdbc?

• To insert the values into the table we use prepared statement.

• PreparedStatement ps = con.prepareStatement("insert into
  Table_name(col1,col2)values(?,?)");//creating preparedstatement

  ps.setInt(1,value_col1);//inserting the value in column1
  ps.setString(2, “value_col2”); //inserting the value in column2

  ps.executeUpdate();//to execute the prepared statement
How to update values in table using jdbc?

• To update the values into the table also we use prepared statement.

• PreparedStatement ps = con.prepareStatement(“update Table_name set
  col1=?,col2=? where col1=?);//creating preparedstatement

  ps.setInt(1,new_value_col1);//updating new value in column1
  ps.setString(2, “value_col2”); //updating the value in column2
  ps.setInt(1,old_value_col1);//getting old value of column1
  ps.executeUpdate();//to execute the prepared statement
How to delete record in table using jdbc?

• To delete the record in the table also we use prepared statement.

• PreparedStatement ps = con.prepareStatement(“delete from Table_name
  where col1=?); //creating preparedstatement

  ps.setInt(1,old_value_col1);//getting value of column1
  ps.executeUpdate();//to execute the prepared statement
How to retrieve record from table using jdbc?

• To store the retrieved records we should use ResultSet.

• ResultSet rs = st.executeQuery("select * from Employee"); //using
  result set to store the result
  while(rs.next())
  {
  System.out.println(rs.getInt(1)); //to retrieve value of col1
  System.out.println(rs.getString(2)); //to retrieve value of
                                          col2
  }
•Q& A..?
Thanks..!

Más contenido relacionado

La actualidad más candente (19)

SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
8. sql
8. sql8. sql
8. sql
 
Sql DML
Sql DMLSql DML
Sql DML
 
Dml and ddl
Dml and ddlDml and ddl
Dml and ddl
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
Sql commands
Sql commandsSql commands
Sql commands
 
STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGESTRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE
 
Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)
 
DML Commands
DML CommandsDML Commands
DML Commands
 
1 ddl
1 ddl1 ddl
1 ddl
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 

Destacado

Java class 1
Java class 1Java class 1
Java class 1Edureka!
 
Java class 7
Java class 7Java class 7
Java class 7Edureka!
 
Java class 4
Java class 4Java class 4
Java class 4Edureka!
 
Java class 5
Java class 5Java class 5
Java class 5Edureka!
 
Java class 3
Java class 3Java class 3
Java class 3Edureka!
 
Java class 6
Java class 6Java class 6
Java class 6Edureka!
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...Edureka!
 

Destacado (8)

Java class 1
Java class 1Java class 1
Java class 1
 
Java class 7
Java class 7Java class 7
Java class 7
 
Java class 4
Java class 4Java class 4
Java class 4
 
Java
Java Java
Java
 
Java class 5
Java class 5Java class 5
Java class 5
 
Java class 3
Java class 3Java class 3
Java class 3
 
Java class 6
Java class 6Java class 6
Java class 6
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
 

Similar a Database Fundamentals: Structured Query Language (SQL) and Java Database Connectivity (JDBC

DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxjainendraKUMAR55
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)PadmapriyaA6
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.pptMARasheed3
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptxRajendra Jain
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan Aslam
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 

Similar a Database Fundamentals: Structured Query Language (SQL) and Java Database Connectivity (JDBC (20)

2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
Adbms
AdbmsAdbms
Adbms
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
SQL | DML
SQL | DMLSQL | DML
SQL | DML
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)
 
SQL
SQLSQL
SQL
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Dbms
DbmsDbms
Dbms
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptx
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 

Más de Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaEdureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

Más de Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Último

4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 

Último (20)

4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 

Database Fundamentals: Structured Query Language (SQL) and Java Database Connectivity (JDBC

  • 2. What is Database ? • Database is a collection of data in an organized way so that we can update, modify data present in database easily. • Data storage in database is permanent. • Eg: Oracle, MySQL, MS-Access, DB2, Sybase
  • 3. How to store data in database? • Data will stored in “Tables” in database in the form of “Records”. • Table is a collection of relational data in 2D i.e in the form of rows and columns.
  • 4. What is SQL ? • SQL – Structure Query Language • It is language used to access and modify the data stored in database. • It uses statements to access the database. • SQL Statements can be divided into two types: DML DDL
  • 5. DDL(Data Definition Language) • These statements are used for creation or deletion of database. • The commands present in DDL are: Create Alter Drop
  • 6. Create • This command is used to create table or database. • create database;//to create database • create table table_name(column1_name datatype,column2_name datatype); // to create table
  • 7. Alter • This command is used to rename a table or column name of an existing table. • It can also be used to modify, add, drop a column/field present in an existing table. • alter table table_name rename new_table_name; //to rename table • alter table table_name rename column old_column_name to new_column_name; //to rename column
  • 8. Alter • alter table table_name add column_name datatype; //to add a column to table • alter table table_name modify column_name new_datatype; //to modify datatype of column of a table • alter table table_name drop column column_name; //to drop a column of a table
  • 9. Drop • This command is used to remove an object(value). • We can not get the table or values in it once the table is dropped. • drop table table_name; //to drop a table
  • 10. DML(Data Manipulation Language) • These statements are used for managing the data in database. • The commands present in DDL are: Insert Update Delete Select
  • 11. Insert • This command is used to enter the records into the table. • insert into table_name values(‘value_col_1’, ‘value_col_2’); //to insert values into table
  • 12. Update • This command is used to update the value of a record or column of a table. • We use condition to know where the updation is to be made. • update table set column_name=“value” where some_column_name = “value_of_some_column”; //to update the column where it satisfies condition
  • 13. Delete • This command is used to delete the records (one or many) from a table by specifying some condition where to delete the record. • delete from table_name where column_name = “value”; //to delete record where it satisfies given condition
  • 14. select • Select command is used to retrieve the records from the table. • select column1_name, column2_name,…………. from table_name; //to select the specific columns from table • select * from table_name; // to retrieve all records present in table
  • 15. Integrity Constraints • Not Null • Unique • Primary Key • Foreign Key • Check
  • 16. Not Null • It is a constraint that ensures that every row is filled with some value for the column which has been specified as “not null”. • create table table_name (column1_name datatype NOT NULL, column2_name datatype );
  • 17. Unique • It is a constraint used for column of a table so that rows of that column should be unique. • It allows null value also. • create table table_name( column1_name datatype UNIQUE, column2_name datatype);
  • 18. Primary Key • It is a constraint used for a column of a table so that we can identify a row in a table uniquely. • create table table_name( • column1_name datatype PRIMARY KEY, • column2_name datatype);
  • 19. Foreign key • It is a constraint used to establish a relationship between two columns in the same or different tables. • For a column to be defined as a Foreign Key, it should be a defined as a Primary Key in the table which it is referring. • One or more columns can be defined as Foreign key. • This constraint identifies any column referencing the PRIMARY KEY in another table.
  • 20. SQL clauses • select • order by • from • group by • where • having • update
  • 21. Order by • This clause is used the values of a column in ascending or descending order. • select empname from emp1 order by empname;
  • 22. Group by • This clause is used to collect data across multiple records and group results by one or more columns. • select department from Student where subject1> 20 group by department;
  • 23. Having • This clause is used in combination with sql group by clause. • It is used to filter the records that a sql group by returns. • select max(subject1) from Student group by department having min(subject1)>20;
  • 24. Basic Functions • COUNT() – to count the number of records satisfy condition. • MAX()- to find the maximum value of a column of all the records present in table. • MIN()- to find the minimum value of a column of all the records present in table. • AVG()- to find the average value of a column of all the records present in table. • SUM()- to find the sum of all the values of a column in a table.
  • 25. Basic Functions • AVG()- to find the average value of a column of all the records present in table. • SUM()- to find the sum of all the values of a column in a table. • Distinct() - to find the distinct record of a table
  • 26. Joins • Join is used to retrieve data from two or more database tables. • Joins are of four types:  Cross join- This join returns the combination of each row of the first table with every column of second table.  Inner join-This join will return the rows from both the tables when it satisfies the given condition.
  • 27. Joins  Left Outer join –suppose if we have two tables. One on the left and the other on right side. When left outer join is applied on these two tables it returns all records of the left side table even if no matching rows are found in right side table  Right Outer join- it is converse of left outer join. It returns all the rows of the right side table even if no matching rows are found in left side table.
  • 28. JDBC
  • 29. JDBC • JDBC-Java Database Connectivity. • JDBC is an API that helps us to connect our java program to the database and do the manipulation of the data through java program.
  • 30. How to write a program in jdbc? • Register the Driver • Connecting to database • Create SQL statement in java • Execute SQL statements • Retrieve Result • Close Connection
  • 31. JDBC program public class JDBCProgram{ public static void main(String[] args) { try { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);//REGISTERING DATABASE Connection con = DriverManager.getConnection("jdbc:odbc:dsn", "",""); //CONNECTING DATABASE Statement st=con.createStatement();//CREATE STATEMENT st.execute("create table Employee(empid integer, empname varchar(50))");//EXECUTING STATEMENT st.close();// CLOSING STATEMENT con.close();//CLOSING CONNECTION } catch (Exception err) { System.out.println( "Error: " + err ); } } }
  • 32. How to insert values into table using jdbc? • To insert the values into the table we use prepared statement. • PreparedStatement ps = con.prepareStatement("insert into Table_name(col1,col2)values(?,?)");//creating preparedstatement ps.setInt(1,value_col1);//inserting the value in column1 ps.setString(2, “value_col2”); //inserting the value in column2 ps.executeUpdate();//to execute the prepared statement
  • 33. How to update values in table using jdbc? • To update the values into the table also we use prepared statement. • PreparedStatement ps = con.prepareStatement(“update Table_name set col1=?,col2=? where col1=?);//creating preparedstatement ps.setInt(1,new_value_col1);//updating new value in column1 ps.setString(2, “value_col2”); //updating the value in column2 ps.setInt(1,old_value_col1);//getting old value of column1 ps.executeUpdate();//to execute the prepared statement
  • 34. How to delete record in table using jdbc? • To delete the record in the table also we use prepared statement. • PreparedStatement ps = con.prepareStatement(“delete from Table_name where col1=?); //creating preparedstatement ps.setInt(1,old_value_col1);//getting value of column1 ps.executeUpdate();//to execute the prepared statement
  • 35. How to retrieve record from table using jdbc? • To store the retrieved records we should use ResultSet. • ResultSet rs = st.executeQuery("select * from Employee"); //using result set to store the result while(rs.next()) { System.out.println(rs.getInt(1)); //to retrieve value of col1 System.out.println(rs.getString(2)); //to retrieve value of col2 }