SlideShare a Scribd company logo
SQL Fundamentals
Oracle 11g
M U H A M M A D WA H E E D
O R AC L E D ATA BA S E D E V E LO P E R
E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m
.
1
Lecture#1
What is SQL?
•Structured Query language (SQL) pronounced as "S-Q-L" or sometimes
as "See- Quel”( interrogate)
•It is language for operating Databases.
•It can be effectively used to insert, search, update, delete records
optimizing and maintenance of databases.
•Mostly databases use SQL like MySQL Database, Oracle, MS SQL server,
Sybase etc.
• How to use SQL syntaxes?
2
Writing SQL Statements
•SQL statements are not case-sensitive. But we will use
UPPERCASE letters for syntax and lowercase for user-defined
data.
•SQL statements can be on one or more lines.
•Keywords cannot be abbreviated or split across lines.
•Clauses are usually placed on separate lines.
•Indents are used to enhance readability.
•In iSQL*Plus, SQL statements can optionally be terminated
by a semicolon(;).
•In SQL*Plus, you are required to end each SQL statement
with a semicolon(;).
3
Naming conventions of SQL
(General)
•Name will be unique and does not exist as a reserved/keyword.
•Can have maximum of 30 characters.
•Use letters, numbers & underscores ( _ ) in names.
•Names must begin with a letter and not end with ( _ ).
•Avoid consecutive underscores. e.g. first__name
•Use underscores instead of space.
•Names should be meaningful.
•If you have to use abbreviation make sure they are commonly
understood.
4
SQL statements
5
Connect DBMS
•There are different user categories due to security/access
control.
•Database Administrators
•Application Developers
•Application Administrators
•Database Users
•Here is the link to Oracle’s site for detailed knowledge on
user types and their roles:
https://docs.oracle.com/cd/B28359_01/server.111/b28310/
dba001.htm#ADMIN11013
6
Database Users(Administrator)
•In addition to the user accounts that you create,
the database includes several user accounts that
are automatically created upon installation.
•In addition to the user accounts that you create,
the database includes several user accounts that
are automatically created upon installation.
•All databases include the administrative accounts
SYS, SYSTEM, SYSMAN.
7
Create new user/database
•There are following steps for creating:
•SQL>CREATE USER <username> IDENTIFIED
BY <password>
•SQL>GRANT DBA TO <username>
•SQL>COMMIT;
•SQL>EXIT;
8
Current User
•Here is the command to check which user is currently
logged in.
•SQL> SHOW USER
9
Tables/Relations/Entities
•Let we have a small database named as uaar which deals with student,
department ,subject and teacher.
•We will perform all of our operations depending upon the defined
structure as below:
•Student (std_id , std_name , std_dept_id, d_o_b , age)
•Teacher (tch_id ,tch_name , tch_qualification)
•Department (dept_id , dept_name)
•Subject (sub_id , sub_title , credit_hour)
•Result (exam_id, sub_id, tch_id , total_marks , exam_date)
•Sub_result (exam_id , std_id , obt_marks , percentage )
10
ERD of UAAR
11
Data Definition
12
Create Table
•We use SQL statement for creating/defining new table with
“CREATE”keyword and following syntax:
•SQL> CREATE TABLE <table_name>
•( <column_name> <data_type>,
•<column_name> <data_type>,
•<column_name> <data_type> );
13
Alter Table
•In case, you have some new data definition to add or want to
edit/delete existing data definitions use this SQL command with
keyword “ALTER” and following syntax:
•SQL> ALTER TABLE <table_name>
ADD <column_name> <data_type>;
•SQL> ALTER TABLE <table_name>
DROP COLUMN <column_name>;
•SQL> ALTER TABLE <table_name>
MODIFY COLUMN <column_name> <data_type>;
•*Note: Some database systems don’t allow to drop a column.
14
Rename Table
•The RENAME statement is used to assign a new name to the existing
table.
•Rename statement has following syntax:
•SQL> ALTER TABLE <table_name>
RENAME TO <new_table_name>;
15
Drop/Delete Table
•The DROP statement is used to delete a table along with table
structure,attributes and data.
•Drop statement has following syntax:
•SQL> DROP <table_name>;
16
Truncate Table
•The TRUNCATE statement is used to delete all data in a table . It does
not delete table structure or attributes.
•TRUNCATE statement has following syntax:
•SQL> TRUNCATE <table_name>;
17
COMMENTS
•Use the COMMENT statement to add to the data dictionary a comment
about a table or table column etc.
•We use following syntax for creating comments:
•COMMENT ON COLUMN <column_name>
IS ‘<comment_statement>';
•We use following syntax to remove comments:
•COMMENT ON COLUMN <column_name> IS ' ';
18
Your Suggestions?
19
“We all need people who will give us feedback. That’s how we improve.”
– Bill Gates
Would like to hear at
m.waheed3668@gmail.com

More Related Content

What's hot

Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
Vivek Singh
 

What's hot (19)

Sql commands
Sql commandsSql commands
Sql commands
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERE
 
1 ddl
1 ddl1 ddl
1 ddl
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Sql commands
Sql commandsSql commands
Sql commands
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 

Similar to SQL Fundamentals - Lecture 2

xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
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
PavithSingh
 
Structured Query Language (SQL).pptx
Structured Query Language (SQL).pptxStructured Query Language (SQL).pptx
Structured Query Language (SQL).pptx
EllenGracePorras
 

Similar to SQL Fundamentals - Lecture 2 (20)

SQL_NOTES.pdf
SQL_NOTES.pdfSQL_NOTES.pdf
SQL_NOTES.pdf
 
SQL basics.pptx
SQL basics.pptxSQL basics.pptx
SQL basics.pptx
 
create database.pptx
create database.pptxcreate database.pptx
create database.pptx
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
 
SQL Intro
SQL IntroSQL Intro
SQL Intro
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
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
 
Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
SQL Create Database.pptx
SQL Create Database.pptxSQL Create Database.pptx
SQL Create Database.pptx
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Structured Query Language (SQL).pptx
Structured Query Language (SQL).pptxStructured Query Language (SQL).pptx
Structured Query Language (SQL).pptx
 
lovely
lovelylovely
lovely
 

Recently uploaded

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

SQL Fundamentals - Lecture 2

  • 1. SQL Fundamentals Oracle 11g M U H A M M A D WA H E E D O R AC L E D ATA BA S E D E V E LO P E R E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m . 1 Lecture#1
  • 2. What is SQL? •Structured Query language (SQL) pronounced as "S-Q-L" or sometimes as "See- Quel”( interrogate) •It is language for operating Databases. •It can be effectively used to insert, search, update, delete records optimizing and maintenance of databases. •Mostly databases use SQL like MySQL Database, Oracle, MS SQL server, Sybase etc. • How to use SQL syntaxes? 2
  • 3. Writing SQL Statements •SQL statements are not case-sensitive. But we will use UPPERCASE letters for syntax and lowercase for user-defined data. •SQL statements can be on one or more lines. •Keywords cannot be abbreviated or split across lines. •Clauses are usually placed on separate lines. •Indents are used to enhance readability. •In iSQL*Plus, SQL statements can optionally be terminated by a semicolon(;). •In SQL*Plus, you are required to end each SQL statement with a semicolon(;). 3
  • 4. Naming conventions of SQL (General) •Name will be unique and does not exist as a reserved/keyword. •Can have maximum of 30 characters. •Use letters, numbers & underscores ( _ ) in names. •Names must begin with a letter and not end with ( _ ). •Avoid consecutive underscores. e.g. first__name •Use underscores instead of space. •Names should be meaningful. •If you have to use abbreviation make sure they are commonly understood. 4
  • 6. Connect DBMS •There are different user categories due to security/access control. •Database Administrators •Application Developers •Application Administrators •Database Users •Here is the link to Oracle’s site for detailed knowledge on user types and their roles: https://docs.oracle.com/cd/B28359_01/server.111/b28310/ dba001.htm#ADMIN11013 6
  • 7. Database Users(Administrator) •In addition to the user accounts that you create, the database includes several user accounts that are automatically created upon installation. •In addition to the user accounts that you create, the database includes several user accounts that are automatically created upon installation. •All databases include the administrative accounts SYS, SYSTEM, SYSMAN. 7
  • 8. Create new user/database •There are following steps for creating: •SQL>CREATE USER <username> IDENTIFIED BY <password> •SQL>GRANT DBA TO <username> •SQL>COMMIT; •SQL>EXIT; 8
  • 9. Current User •Here is the command to check which user is currently logged in. •SQL> SHOW USER 9
  • 10. Tables/Relations/Entities •Let we have a small database named as uaar which deals with student, department ,subject and teacher. •We will perform all of our operations depending upon the defined structure as below: •Student (std_id , std_name , std_dept_id, d_o_b , age) •Teacher (tch_id ,tch_name , tch_qualification) •Department (dept_id , dept_name) •Subject (sub_id , sub_title , credit_hour) •Result (exam_id, sub_id, tch_id , total_marks , exam_date) •Sub_result (exam_id , std_id , obt_marks , percentage ) 10
  • 13. Create Table •We use SQL statement for creating/defining new table with “CREATE”keyword and following syntax: •SQL> CREATE TABLE <table_name> •( <column_name> <data_type>, •<column_name> <data_type>, •<column_name> <data_type> ); 13
  • 14. Alter Table •In case, you have some new data definition to add or want to edit/delete existing data definitions use this SQL command with keyword “ALTER” and following syntax: •SQL> ALTER TABLE <table_name> ADD <column_name> <data_type>; •SQL> ALTER TABLE <table_name> DROP COLUMN <column_name>; •SQL> ALTER TABLE <table_name> MODIFY COLUMN <column_name> <data_type>; •*Note: Some database systems don’t allow to drop a column. 14
  • 15. Rename Table •The RENAME statement is used to assign a new name to the existing table. •Rename statement has following syntax: •SQL> ALTER TABLE <table_name> RENAME TO <new_table_name>; 15
  • 16. Drop/Delete Table •The DROP statement is used to delete a table along with table structure,attributes and data. •Drop statement has following syntax: •SQL> DROP <table_name>; 16
  • 17. Truncate Table •The TRUNCATE statement is used to delete all data in a table . It does not delete table structure or attributes. •TRUNCATE statement has following syntax: •SQL> TRUNCATE <table_name>; 17
  • 18. COMMENTS •Use the COMMENT statement to add to the data dictionary a comment about a table or table column etc. •We use following syntax for creating comments: •COMMENT ON COLUMN <column_name> IS ‘<comment_statement>'; •We use following syntax to remove comments: •COMMENT ON COLUMN <column_name> IS ' '; 18
  • 19. Your Suggestions? 19 “We all need people who will give us feedback. That’s how we improve.” – Bill Gates Would like to hear at m.waheed3668@gmail.com