The document provides an overview of SQL commands and operations including:
1) Creating a database and table, inserting and selecting data, updating records with WHERE clauses.
2) Altering tables by adding or modifying columns and constraints.
3) Different SQL statements like SELECT, INSERT, UPDATE and DELETE and clauses like WHERE are discussed along with syntax and examples.
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
2.
quick introduction of SQL
create database and table
change table(new column, update column)
Insert query
select query
where clauses
update query
delete query
create an index
group by query
1
Chapter Outline
3.
What is SQL?
SQL is Structured Query Language, which is a computer
language for storing, manipulating and retrieving data
stored in a relational database.
SQL is the standard language for Relational Database
System.
All the Relational Database Management Systems
(RDMS) like MySQL, MS Access, Oracle, Sybase,
Informix, Postgres and SQL Server use SQL as their
standard database language.
2
Quick introduction of SQL
4.
The standard SQL commands to interact with
relational databases are CREATE, SELECT, INSERT,
UPDATE, DELETE and DROP. These commands can
be classified into the following groups based on their
nature:-
DDL - Data Definition Language
DML - Data Manipulation Language
DCL - Data Control Language
3
SQL Commands
8.
Characteristics Of SQL Commands
Here you can see that SQL commands follow a number of basic
rules:
SQL keywords are not normally case sensitive, though this in
this tutorial all commands (SELECT, UPDATE etc) are upper-
cased.
Variable and parameter names are displayed here as lower-
case.
New-line characters are ignored in SQL, so a command may
be all on one line or broken up across a number of lines for
the sake of clarity.
Many DBMS systems expect to have SQL commands
terminated with a semicolon character.
7
SQL - Syntax
10.
create database
The SQL CREATE DATABASE statement is used to create a new SQL
database.
Syntax
The basic syntax of this CREATE DATABASE statement is as follows :-
CREATE DATABASE DatabaseName;
Always the database name should be unique within the RDBMS.
Example
If you want to create a new database <studentDB>, then the CREATE
DATABASE statement would be as shown below :-
CREATE DATABASE studentDB;
Make sure you have the admin privilege before creating any database
9
create database and table
11.
Steps in Table Creation
1. Identify data types for attributes
2. Identify columns that can and cannot be null
3. Identify columns that must be unique (candidate keys)
4. Identify primary key–foreign key mates
5. Determine default values
6. Identify constraints on columns (domain specifications)
7. Create the table and associated indexes 10
create table
12.
Create table
Creating a basic table involves naming the table and defining its columns and each
column's data type.
The SQL CREATE TABLE statement is used to create a new table.
Syntax
The basic syntax of the CREATE TABLE statement is as follows :-
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
); 11
create database and table
13.
CREATE TABLE is the keyword telling the database
system what you want to do. In this case, you want to
create a new table. The unique name or identifier for
the table follows the CREATE TABLE statement.
Then in brackets comes the list defining each column
in the table and what sort of data type it is. The
syntax becomes clearer with the following example.
A copy of an existing table can be created using a
combination of the CREATE TABLE statement and
the SELECT statement.
12
create table(contd.)
14.
Example
The following code block is an example, which creates a CUSTOMERS table with an ID as a
primary key and NOT NULL are the constraints showing that these fields cannot be NULL
while creating records in this table :-
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25) ,
SALARY DECIMAL (18, 2),
PRIMARY KEY (ID)
);
You can verify if your table has been created successfully by looking at the message displayed by
the SQL server 13
create table(contd.)
15.
The SQL ALTER TABLE command is used to add, delete or modify columns in
an existing table. You should also use the ALTER TABLE command to add and
drop various constraints on an existing table.
Syntax
The basic syntax of an ALTER TABLE command to add a New Column in an
existing table is as follows.
ALTER TABLE table_name ADD column_name datatype;
The basic syntax of an ALTER TABLE command to DROP COLUMN in an
existing table is as follows.
ALTER TABLE table_name DROP COLUMN column_name;
The basic syntax of an ALTER TABLE command to change the DATA TYPE of
a column in a table is as follows.
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
14
Change table(new column, update column)
16.
The basic syntax of an ALTER TABLE command to add a NOT NULL
constraint to a column in a table is as follows.
ALTER TABLE table_name MODIFY column_name datatype NOT NULL;
The basic syntax of ALTER TABLE to ADD UNIQUE CONSTRAINT to a table
is as follows.
ALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint
UNIQUE(column1, column2...);
The basic syntax of an ALTER TABLE command to ADD CHECK
CONSTRAINT to a table is as follows.
ALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint CHECK
(CONDITION);
The basic syntax of an ALTER TABLE command to ADD PRIMARY KEY
constraint to atable is as follows.
ALTER TABLE table_name ADD CONSTRAINT MyPrimaryKey PRIMARY KEY
(column1, column2...); 15
Change table(new column, update column)
17.
The basic syntax of an ALTER TABLE command to ADD PRIMARY KEY
constraint to atable is as follows.
ALTER TABLE table_name ADD CONSTRAINT MyPrimaryKey PRIMARY KEY
(column1, column2...);
The basic syntax of an ALTER TABLE command to DROP CONSTRAINT
from a table is as follows.
ALTER TABLE table_name DROP CONSTRAINT MyUniqueConstraint;
The basic syntax of an ALTER TABLE command to DROP PRIMARY KEY
constraint from a table is as follows.
ALTER TABLE table_name DROP CONSTRAINT MyPrimaryKey;
16
Create a primary key
18.
The SQL INSERT INTO Statement is used to add new rows of data
to a table in the database.
Syntax
There are two basic syntaxes of the INSERT INTO statement which
are shown below.
INSERT INTO TABLE_NAME (column1, column2,
column3,...columnN)VALUES (value1, value2, value3,...valueN);
Here, column1, column2, column3,...columnN are the names of the
columns in the table into which you want to insert the data.
You may not need to specify the column(s) name in the SQL query if
you are adding values for all the columns of the table. But make sure
the order of the values is in the same order as the columns in the
table.
17
Insert data into table
19.
The SQL INSERT INTO syntax will be as follows
INSERT INTO TABLE_NAME VALUES(value1,value2,value3,...valueN);
Example
The following statements would create two records in the
CUSTOMERS table.
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00 );
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)VALUES
(2, 'Khilan', 25, 'Delhi', 1500.00 );
You can create a record in the CUSTOMERS table by using the
second syntax as shown below.
INSERT INTO CUSTOMERS VALUES (3, 'Muffy', 24, 'Indore',
10000.00 );
18
Insert (contd.)
20.
Select database
When you have multiple databases in your SQL Schema, then before
starting your operation, you would need to select a database where
all the operations would be performed.
The SQL USE statement is used to select any existing database in the
SQL schema.
Syntax
The basic syntax of the USE statement is as shown below :-
USE DatabaseName;
Always the database name should be unique within the RDBMS.
Example
Use studentDB; to select studentDB.
19
select database
21.
The SQL SELECT statement is used to fetch the data from a database
table which returns this data in the form of a result table. These result
tables are called result-sets.
Syntax
The basic syntax of the SELECT statement is as follows :-
SELECT column1, column2, columnN FROM table_name;
Here, column1, column2... are the fields of a table whose values you
want to fetch. If you want to fetch all the fields available in the field,
then you can use the following syntax.
SELECT * FROM table_name;
20
SELECT Query
23.
If you want to fetch all the fields of the CUSTOMERS table, then you
should use the following query.
SELECT * FROM CUSTOMERS;
This would produce the result as shown below.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+ 22
SELECT Query
24.
The SQL clause is used to specify a condition while fetching
the data from a single table or by joining with multiple
tables. If the given condition is satisfied, then only it
returns a specific value from the table. You should use the
WHERE clause to filter the records and fetching only the
necessary records.
The WHERE clause is not only used in the SELECT
statement, but it is also used in the UPDATE, DELETE
statement, etc., which we would examine in the subsequent
sections.
23
where clauses
25.
Syntax
The basic syntax of the SELECT statement with the WHERE clause is as
shown below.
SELECT column1, column2, columnN FROM table_name WHERE
[condition]
You can specify a condition using the comparison or logical operators
like >, <, =, LIKE,
NOT, etc. The following examples would make this concept clear.
Example
Consider the CUSTOMERS table having the following
records above
24
where clauses
26.
The following code is an example which would fetch the ID, Name and
Salary fields from the CUSTOMERS table, where the salary is greater
than 2000
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERSWHERE
SALARY > 2000;
This would produce the following result
+----+----------+----------+
| ID | NAME | SALARY |
+----+----------+----------+
| 4 | Chaitali | 6500.00 |
| 5 | Hardik | 8500.00 |
| 6 | Komal | 4500.00 |
| 7 | Muffy | 10000.00 |
+----+----------+----------+
25
where clauses
27.
The following query is an example, which would fetch the ID, Name and Salary
fields from the CUSTOMERS table for a customer with the name Hardik.
Here, it is important to note that all the strings should be given inside single
quotes ('').Whereas, numeric values should be given without any quote as in
the above example.
SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE NAME = 'Hardik';
This would produce the following result
+----+----------+----------+
| ID | NAME | SALARY |
+----+----------+----------+
| 5 | Hardik | 8500.00 |
+----+----------+----------+ 26
where clauses
28.
The SQL UPDATE Query is used to modify the existing records in a table. You
can use the WHERE clause with the UPDATE query to update the selected
rows, otherwise all the rows would be affected.
Syntax
The basic syntax of the UPDATE query with a WHERE clause is as follows :-
UPDATE table_name SET column1 = value1, column2 = value2...., columnN =
valueN WHERE [condition];
You can combine N number of conditions using the AND or the OR operators.
The following query will update the ADDRESS for a customer whose ID
number is 6 in the customer table.
UPDATE CUSTOMERS SET ADDRESS = 'Pune‘ WHERE ID = 6;
27
Update query
29.
If you want to modify all the ADDRESS and the SALARY column values in the
CUSTOMERS table, you do not need to use the WHERE clause as the UPDATE
query would be enough as shown in the following code block.
UPDATE CUSTOMERS SET ADDRESS = 'Pune', SALARY = 1000.00;
28
Update query
30.
The SQL DELETE Query is used to delete the existing records from a table. You
can use the WHERE clause with a DELETE query to delete the selected rows,
otherwise all the records would be deleted.
Syntax
The basic syntax of the DELETE query with the WHERE clause is as follows :-
DELETE FROM table_name WHERE [condition];
You can combine N number of conditions using AND or OR operators.
The following code has a query, which will DELETE a customer, whose ID is 6.
DELETE FROM CUSTOMERS WHERE ID = 6;
If you want to DELETE all the records from the CUSTOMERS table, you do not
need to use the WHERE clause and the DELETE query would be as follows −
DELETE FROM CUSTOMERS;
Now, the CUSTOMERS table would not have any record. 29
Delete query
31.
Indexes are special lookup tables that the database search engine can
use to speed up data retrieval. Simply put, an index is a pointer to data
in a table. An index in a database is very similar to an index in the back
of a book.
An index helps to speed up SELECT queries and WHERE clauses, but
it slows down data input, with the UPDATE and the INSERT
statements. Indexes can be created or dropped with no effect on the
data.
Creating an index involves the CREATE INDEX statement, which
allows you to name the index, to specify the table and which column or
columns to index, and to indicate whether the index is in an ascending
or descending order.
Indexes can also be unique, like the UNIQUE constraint, in that the
index prevents duplicate entries in the column or combination of
columns on which there is an index. 30
create an index
32.
The basic syntax of a CREATE INDEX is as follows.
CREATE INDEX index_name ON table_name;
Single-Column Indexes
A single-column index is created based on only one table column. The
basic syntax is as follows.
CREATE INDEX index_name ON table_name (column_name);
Unique Indexes
Unique indexes are used not only for performance, but also for data
integrity. A unique
index does not allow any duplicate values to be inserted into the table.
The basic syntax is as follows.
CREATE UNIQUE INDEX index_name on table_name (column_name);
31
The CREATE INDEX Command
33.
A composite index is an index on two or more columns of a table. Its
basic syntax is as follows.
CREATE INDEX index_name on table_name (column1, column2);
Whether to create a single-column index or a composite index, take into
consideration the column(s) that you may use very frequently in a
query's WHERE clause as filter conditions.
The DROP INDEX Command
An index can be dropped using SQL DROP command. Care should be
taken when dropping an index because the performance may either
slow down or improve.
The basic syntax is as follows :-
DROP INDEX index_name;
32
Composite Indexes
34.
The SQL GROUP BY clause is used in collaboration with the SELECT
statement to arrange identical data into groups. This GROUP BY clause
follows the WHERE clause in a SELECT tatement and precedes the
ORDER BY clause.
Syntax
The basic syntax of a GROUP BY clause is shown in the following code
block. The GROUP BY clause must follow the conditions in the
WHERE clause and must precede the ORDER BY clause if one is used.
SELECT column1, column2 FROM table_name WHERE [ conditions ]
GROUP BY column1, column2 ORDER BY column1, column2
33
SQL GROUP BY