SlideShare a Scribd company logo
2
STRUCTURE OF RELATIONAL DATABASES:
RDBMS in which data is stored in the form of tables. A relational
database consists of a collection of tables, each of which is assigned a unique
name.
BASIC STRUCTURE
Each column header is attributes. Each attribute allows a set of permitted
values called domain of that attribute.
 Table is called as a relation and rows in a table are called as tuples.
 The tuples in a relation can be either sorted or unsorted.
 Several attributes can have same domain. E.g.: customer_name,
employee_name.
 Attributes can also be distinct. E.g.: balance, branch_name
 Attributes can have null values incase if the value is unknown or does
not exist.
Account Table
What is Query?
 A query is a question.
 A query is formulated for a relation/table to retrieve some useful
information from the table.
Data Definition Language (DDL) Commands:
Command Description
CREATE Creates a new table, a view of a table in the database
ALTER Modifies an existing table; used to add a new column,
modify the existing column definition and to include or
drop integrity constraint.
DROP Deletes an entire table, a view of a table in the database.
It will delete the table structure
Most read
6
Example:
DROP TABLE Orders;
The TRUNCATE TABLE Statement
An easier and faster way of removing all rows from a table is using the
TRUNCATE command.
Syntax
TRUNCATE TABLE tablename;
Example
TRUNCATE TABLE Customer;
Data Manipulation Language Commands in SQL
DML commands are the most frequently used SQL commands and is used to
query and manipulate the existing database objects. Some of the commands are
 Insert
 Update
 Delete
The data manipulation statements are:
 The INSERT statement
 The UPDATE statement
 The DELETE statement
The INSERT...VALUES Statement
The INSERT...VALUES statement enters data into a table one record at a
time.
The first form does not specify the column names where the data will be inserted,
only their values:
INSERT INTO table_name VALUES (value1, value2...)
The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (col1, col2...) VALUES (value1, value2...)
Most read
7
The DELETE Statement
In addition to adding data to a database, you will also need to delete data
from a database. The syntax for the DELETE statement is
Syntax
DELETE FROM tablename WHERE condition;
Depending on the use of the DELETE statement's WHERE clause, SQL can do
the following:
 Delete single rows
 Delete multiple rows
 Delete all rows
Here are several points to remember when using the DELETE statement:
 The DELETE statement cannot delete an individual field's values. The
DELETE statement deletes entire records from a single table.
 Using the DELETE statement deletes only records, not the table itself.
Use the DROP TABLE statement to remove an entire table.
Delete All Data - It is possible to delete all rows in a table without deleting the
table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM table_name; (OR)
DELETE * FROM table_name;
Exercise:
Most read
SQL (pronounced sequel) is an acronym for Structured Query Language, a
standardized language used to access and manipulate data.
SQL enables a programmer or database administrator to do the following:
 Modify a database's structure
 Change system security settings
 Add user permissions on databases or tables
 Query a database for information
 Update the contents of a database
Guidelines for Writing SQL statements
1. SQL statements are not case sensitive.
2. SQL statements can be on one or more lines.
3. SQL is a free form language.
4. SQL keywords are typically entered in uppercase; all other words such as
table and column names are entered in lowercase.
5. SQL Statements are terminated with a semi-colon.
6. SQL won't execute the query until it finds a semicolon
Language SQL Commands
Data Definition Language
(DDL)
1. CREATE
2. ALTER
3. DROP
4. TRUNCATE
5. RENAME
Data Manipulation Language
(DML)
1. INSERT
2. UPDATE
3. DELETE
Data Query Language (DQL)  SELECT
Data Control Language
(DCL)
4. GRANT
5. REVOKE
Transaction Control Language
(TCL)
6. COMMIT
7. ROLLBACK
8. SAVEPOINT
STRUCTURE OF RELATIONAL DATABASES:
RDBMS in which data is stored in the form of tables. A relational
database consists of a collection of tables, each of which is assigned a unique
name.
BASIC STRUCTURE
Each column header is attributes. Each attribute allows a set of permitted
values called domain of that attribute.
 Table is called as a relation and rows in a table are called as tuples.
 The tuples in a relation can be either sorted or unsorted.
 Several attributes can have same domain. E.g.: customer_name,
employee_name.
 Attributes can also be distinct. E.g.: balance, branch_name
 Attributes can have null values incase if the value is unknown or does
not exist.
Account Table
What is Query?
 A query is a question.
 A query is formulated for a relation/table to retrieve some useful
information from the table.
Data Definition Language (DDL) Commands:
Command Description
CREATE Creates a new table, a view of a table in the database
ALTER Modifies an existing table; used to add a new column,
modify the existing column definition and to include or
drop integrity constraint.
DROP Deletes an entire table, a view of a table in the database.
It will delete the table structure
TRUNCATE Truncates the table values without deleting table
structure (the records alone will be deleted)
RENAME This is used to change the name of the table
DESC This is used to view the structure of the table
Table Creation Rules:
1. Reserved words cannot be used as table name
2. The first character of the name must be a letter between A and Z, the
remaining characters can be letters or the symbols _, #, $, and @.
3. Underscore, numerals, letters are allowed but not blank space.
4. Maximum length for the table name is 30 characters.
5. 2 different tables should not have same name.
6. We should specify a unique column name for primary key.
7. We should specify proper data type along with width. (Domain type)
8. We can include “not null” condition when needed. By default, it is ‘null’.
The Field's Data Type – Domain type
Data Type Comments
CHAR Alphanumeric data with a length between 1 and 255
characters. Spaces are padded to the right of the value to
supplement the total allocated length of the column.
DATE Included as part of the date as century, year, month, day, hour,
minute, and second.
NUMBER Numeric 0, positive or negative fixed or floating-point data.
VARCHAR2 Alphanumeric data that is variable length; this field must be
between 1 and 2,000 characters long.
The CREATE Syntax
CREATE TABLE <table name>
(
fieldname-1datatype constraints if any,
fieldname-2 datatype constraints if any,
.......
fieldname-n datatype constraints if any,
);
Example
SQL> CREATE TABLE Customer
(
Customer_id int,
Customer_name varchar2(20),
Address varchar2(30),
City varchar2(15)
);
Primary key - it uniquely identifies a row within a table. A table may have only
one primary key, which consists of one or more columns. If the primary key
contains multiple columns it is referred to as a composite primary key or
concatenated primary key.
Syntax
CREATE TABLE <tableName> (<attribute_name> <type> PRIMARY KEY);
CREATE TABLE Student
(
Regno int PRIMARY KEY,
Name varchar2(30),
Marks int
);
Describing the structure of the table
After a table has been created, it may be necessary to determine the name,
data type and some of the constraints of the attributes that compose the table. The
command used is DESC. The syntax of this command is
Syntax
DESC table-name;
SQL> DESC Customer;
Name Type
-----------------------------------------------------
Customer_id int
Customer_name varchar2(20)
Address varchar2(30)
City varchar2(15)
The ALTER TABLE Statement
Many times your database design does not account for everything it should.
The ALTER TABLE statement enables the database administrator or
designer to change the structure of a table after it has been created.
The ALTER TABLE command enables you to do two things:
 Add a column to an existing table
 Modify a column that already exists
 Add constraints to an existing table
 Removing constraints from a table
The syntax for adding and modifying columns:
ALTER TABLE table_name
<ADD column_name data_type; | MODIFY column_name data_type ;>
Example:
ALTER TABLE Customer ADD DateOfBirth int;
Customer_Id Customer_Name Address City DateOfBirth
Change Data Type Example
Now we want to change the data type of the column named "DateOfBirth"
in the "Customers" table. We use the following SQL statement:
Syntax
ALTER TABLE Customers MODIFY COLUMN DateOfBirth year;
If we want to remove a column then
ALTER TABLE Persons DROP COLUMN DateOfBirth;
The DROP TABLE Statement
SQL provides a command to completely remove a table from a database. The
DROP TABLE command deletes a table along with all its associated views and
indexes. After this command has been issued, there is no turning back.
SYNTAX:
DROP TABLE table_name;
Example:
DROP TABLE Orders;
The TRUNCATE TABLE Statement
An easier and faster way of removing all rows from a table is using the
TRUNCATE command.
Syntax
TRUNCATE TABLE tablename;
Example
TRUNCATE TABLE Customer;
Data Manipulation Language Commands in SQL
DML commands are the most frequently used SQL commands and is used to
query and manipulate the existing database objects. Some of the commands are
 Insert
 Update
 Delete
The data manipulation statements are:
 The INSERT statement
 The UPDATE statement
 The DELETE statement
The INSERT...VALUES Statement
The INSERT...VALUES statement enters data into a table one record at a
time.
The first form does not specify the column names where the data will be inserted,
only their values:
INSERT INTO table_name VALUES (value1, value2...)
The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (col1, col2...) VALUES (value1, value2...)
The DELETE Statement
In addition to adding data to a database, you will also need to delete data
from a database. The syntax for the DELETE statement is
Syntax
DELETE FROM tablename WHERE condition;
Depending on the use of the DELETE statement's WHERE clause, SQL can do
the following:
 Delete single rows
 Delete multiple rows
 Delete all rows
Here are several points to remember when using the DELETE statement:
 The DELETE statement cannot delete an individual field's values. The
DELETE statement deletes entire records from a single table.
 Using the DELETE statement deletes only records, not the table itself.
Use the DROP TABLE statement to remove an entire table.
Delete All Data - It is possible to delete all rows in a table without deleting the
table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM table_name; (OR)
DELETE * FROM table_name;
Exercise:

More Related Content

Similar to Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values, display records (20)

unit-5 sql notes.docx
unit-5 sql notes.docxunit-5 sql notes.docx
unit-5 sql notes.docx
RaviRajput416403
 
SQL commands in database managemant systems
SQL commands in database managemant systemsSQL commands in database managemant systems
SQL commands in database managemant systems
pmselvaraj
 
SQL Queries - DDL Commands
SQL Queries - DDL CommandsSQL Queries - DDL Commands
SQL Queries - DDL Commands
ShubhamBauddh
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
lovely
lovelylovely
lovely
love0323
 
Introduction to SQl Commands.pptxhhjhvvb
Introduction to SQl Commands.pptxhhjhvvbIntroduction to SQl Commands.pptxhhjhvvb
Introduction to SQl Commands.pptxhhjhvvb
DeepakSingh99214
 
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
 
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12  CBSESQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12  CBSE
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
ARVIND SARDAR
 
sql.pptx
sql.pptxsql.pptx
sql.pptx
slavskrillex
 
SQL_all_commnads_aggregate_functions.pptx
SQL_all_commnads_aggregate_functions.pptxSQL_all_commnads_aggregate_functions.pptx
SQL_all_commnads_aggregate_functions.pptx
fakee00789
 
SQl data base management and design
SQl     data base management  and designSQl     data base management  and design
SQl data base management and design
franckelsania20
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
Lab
LabLab
Lab
neelam_rawat
 
SQL.pptx structure query language in database management system
SQL.pptx structure query language in database management systemSQL.pptx structure query language in database management system
SQL.pptx structure query language in database management system
ironman82715
 
SQL-1.pptx for database system and system query language
SQL-1.pptx for database system  and system query languageSQL-1.pptx for database system  and system query language
SQL-1.pptx for database system and system query language
ironman82715
 
Database Languages power point presentation
Database Languages power point presentationDatabase Languages power point presentation
Database Languages power point presentation
AshokRachapalli1
 
DBMS UNIT-2.pptx ggggggggggggggggggggggg
DBMS UNIT-2.pptx gggggggggggggggggggggggDBMS UNIT-2.pptx ggggggggggggggggggggggg
DBMS UNIT-2.pptx ggggggggggggggggggggggg
Praveen Kumar
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
Database management system unit 1 Bca 2-semester notes
Database management system  unit 1 Bca 2-semester notesDatabase management system  unit 1 Bca 2-semester notes
Database management system unit 1 Bca 2-semester notes
n32310997
 
SQL commands in database managemant systems
SQL commands in database managemant systemsSQL commands in database managemant systems
SQL commands in database managemant systems
pmselvaraj
 
SQL Queries - DDL Commands
SQL Queries - DDL CommandsSQL Queries - DDL Commands
SQL Queries - DDL Commands
ShubhamBauddh
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
Introduction to SQl Commands.pptxhhjhvvb
Introduction to SQl Commands.pptxhhjhvvbIntroduction to SQl Commands.pptxhhjhvvb
Introduction to SQl Commands.pptxhhjhvvb
DeepakSingh99214
 
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
 
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12  CBSESQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12  CBSE
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
ARVIND SARDAR
 
SQL_all_commnads_aggregate_functions.pptx
SQL_all_commnads_aggregate_functions.pptxSQL_all_commnads_aggregate_functions.pptx
SQL_all_commnads_aggregate_functions.pptx
fakee00789
 
SQl data base management and design
SQl     data base management  and designSQl     data base management  and design
SQl data base management and design
franckelsania20
 
SQL.pptx structure query language in database management system
SQL.pptx structure query language in database management systemSQL.pptx structure query language in database management system
SQL.pptx structure query language in database management system
ironman82715
 
SQL-1.pptx for database system and system query language
SQL-1.pptx for database system  and system query languageSQL-1.pptx for database system  and system query language
SQL-1.pptx for database system and system query language
ironman82715
 
Database Languages power point presentation
Database Languages power point presentationDatabase Languages power point presentation
Database Languages power point presentation
AshokRachapalli1
 
DBMS UNIT-2.pptx ggggggggggggggggggggggg
DBMS UNIT-2.pptx gggggggggggggggggggggggDBMS UNIT-2.pptx ggggggggggggggggggggggg
DBMS UNIT-2.pptx ggggggggggggggggggggggg
Praveen Kumar
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
Database management system unit 1 Bca 2-semester notes
Database management system  unit 1 Bca 2-semester notesDatabase management system  unit 1 Bca 2-semester notes
Database management system unit 1 Bca 2-semester notes
n32310997
 

More from SakkaravarthiS1 (6)

UNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingUNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and Multithreading
SakkaravarthiS1
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
SakkaravarthiS1
 
UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...
UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...
UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...
SakkaravarthiS1
 
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
SakkaravarthiS1
 
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdfUNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
SakkaravarthiS1
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
UNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingUNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and Multithreading
SakkaravarthiS1
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
SakkaravarthiS1
 
UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...
UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...
UNIT-1 PPT.pptCS 3492 DBMS UNIT 1 to 5 overview Unit 1 slides including purpo...
SakkaravarthiS1
 
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
SakkaravarthiS1
 
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdfUNIT 5-JavaFX Event Handling, Controls and Components.pdf
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
SakkaravarthiS1
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
SakkaravarthiS1
 
Ad

Recently uploaded (20)

FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
IntroSlides-June-GDG-Cloud-Munich community [email protected]
IntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdfIntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdf
IntroSlides-June-GDG-Cloud-Munich community [email protected]
Luiz Carneiro
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Ad

Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values, display records

  • 1. SQL (pronounced sequel) is an acronym for Structured Query Language, a standardized language used to access and manipulate data. SQL enables a programmer or database administrator to do the following:  Modify a database's structure  Change system security settings  Add user permissions on databases or tables  Query a database for information  Update the contents of a database Guidelines for Writing SQL statements 1. SQL statements are not case sensitive. 2. SQL statements can be on one or more lines. 3. SQL is a free form language. 4. SQL keywords are typically entered in uppercase; all other words such as table and column names are entered in lowercase. 5. SQL Statements are terminated with a semi-colon. 6. SQL won't execute the query until it finds a semicolon Language SQL Commands Data Definition Language (DDL) 1. CREATE 2. ALTER 3. DROP 4. TRUNCATE 5. RENAME Data Manipulation Language (DML) 1. INSERT 2. UPDATE 3. DELETE Data Query Language (DQL)  SELECT Data Control Language (DCL) 4. GRANT 5. REVOKE Transaction Control Language (TCL) 6. COMMIT 7. ROLLBACK 8. SAVEPOINT
  • 2. STRUCTURE OF RELATIONAL DATABASES: RDBMS in which data is stored in the form of tables. A relational database consists of a collection of tables, each of which is assigned a unique name. BASIC STRUCTURE Each column header is attributes. Each attribute allows a set of permitted values called domain of that attribute.  Table is called as a relation and rows in a table are called as tuples.  The tuples in a relation can be either sorted or unsorted.  Several attributes can have same domain. E.g.: customer_name, employee_name.  Attributes can also be distinct. E.g.: balance, branch_name  Attributes can have null values incase if the value is unknown or does not exist. Account Table What is Query?  A query is a question.  A query is formulated for a relation/table to retrieve some useful information from the table. Data Definition Language (DDL) Commands: Command Description CREATE Creates a new table, a view of a table in the database ALTER Modifies an existing table; used to add a new column, modify the existing column definition and to include or drop integrity constraint. DROP Deletes an entire table, a view of a table in the database. It will delete the table structure
  • 3. TRUNCATE Truncates the table values without deleting table structure (the records alone will be deleted) RENAME This is used to change the name of the table DESC This is used to view the structure of the table Table Creation Rules: 1. Reserved words cannot be used as table name 2. The first character of the name must be a letter between A and Z, the remaining characters can be letters or the symbols _, #, $, and @. 3. Underscore, numerals, letters are allowed but not blank space. 4. Maximum length for the table name is 30 characters. 5. 2 different tables should not have same name. 6. We should specify a unique column name for primary key. 7. We should specify proper data type along with width. (Domain type) 8. We can include “not null” condition when needed. By default, it is ‘null’. The Field's Data Type – Domain type Data Type Comments CHAR Alphanumeric data with a length between 1 and 255 characters. Spaces are padded to the right of the value to supplement the total allocated length of the column. DATE Included as part of the date as century, year, month, day, hour, minute, and second. NUMBER Numeric 0, positive or negative fixed or floating-point data. VARCHAR2 Alphanumeric data that is variable length; this field must be between 1 and 2,000 characters long. The CREATE Syntax CREATE TABLE <table name> ( fieldname-1datatype constraints if any, fieldname-2 datatype constraints if any, ....... fieldname-n datatype constraints if any, ); Example
  • 4. SQL> CREATE TABLE Customer ( Customer_id int, Customer_name varchar2(20), Address varchar2(30), City varchar2(15) ); Primary key - it uniquely identifies a row within a table. A table may have only one primary key, which consists of one or more columns. If the primary key contains multiple columns it is referred to as a composite primary key or concatenated primary key. Syntax CREATE TABLE <tableName> (<attribute_name> <type> PRIMARY KEY); CREATE TABLE Student ( Regno int PRIMARY KEY, Name varchar2(30), Marks int ); Describing the structure of the table After a table has been created, it may be necessary to determine the name, data type and some of the constraints of the attributes that compose the table. The command used is DESC. The syntax of this command is Syntax DESC table-name; SQL> DESC Customer; Name Type ----------------------------------------------------- Customer_id int Customer_name varchar2(20) Address varchar2(30) City varchar2(15)
  • 5. The ALTER TABLE Statement Many times your database design does not account for everything it should. The ALTER TABLE statement enables the database administrator or designer to change the structure of a table after it has been created. The ALTER TABLE command enables you to do two things:  Add a column to an existing table  Modify a column that already exists  Add constraints to an existing table  Removing constraints from a table The syntax for adding and modifying columns: ALTER TABLE table_name <ADD column_name data_type; | MODIFY column_name data_type ;> Example: ALTER TABLE Customer ADD DateOfBirth int; Customer_Id Customer_Name Address City DateOfBirth Change Data Type Example Now we want to change the data type of the column named "DateOfBirth" in the "Customers" table. We use the following SQL statement: Syntax ALTER TABLE Customers MODIFY COLUMN DateOfBirth year; If we want to remove a column then ALTER TABLE Persons DROP COLUMN DateOfBirth; The DROP TABLE Statement SQL provides a command to completely remove a table from a database. The DROP TABLE command deletes a table along with all its associated views and indexes. After this command has been issued, there is no turning back. SYNTAX: DROP TABLE table_name;
  • 6. Example: DROP TABLE Orders; The TRUNCATE TABLE Statement An easier and faster way of removing all rows from a table is using the TRUNCATE command. Syntax TRUNCATE TABLE tablename; Example TRUNCATE TABLE Customer; Data Manipulation Language Commands in SQL DML commands are the most frequently used SQL commands and is used to query and manipulate the existing database objects. Some of the commands are  Insert  Update  Delete The data manipulation statements are:  The INSERT statement  The UPDATE statement  The DELETE statement The INSERT...VALUES Statement The INSERT...VALUES statement enters data into a table one record at a time. The first form does not specify the column names where the data will be inserted, only their values: INSERT INTO table_name VALUES (value1, value2...) The second form specifies both the column names and the values to be inserted: INSERT INTO table_name (col1, col2...) VALUES (value1, value2...)
  • 7. The DELETE Statement In addition to adding data to a database, you will also need to delete data from a database. The syntax for the DELETE statement is Syntax DELETE FROM tablename WHERE condition; Depending on the use of the DELETE statement's WHERE clause, SQL can do the following:  Delete single rows  Delete multiple rows  Delete all rows Here are several points to remember when using the DELETE statement:  The DELETE statement cannot delete an individual field's values. The DELETE statement deletes entire records from a single table.  Using the DELETE statement deletes only records, not the table itself. Use the DROP TABLE statement to remove an entire table. Delete All Data - It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact: DELETE FROM table_name; (OR) DELETE * FROM table_name; Exercise: