Valueble SQL Skills
Valueble SQL Skills
SELECT
1 Retrieves certain records from one or more tables.
INSERT
2 Creates a record.
UPDATE
3 Modifies records.
DELETE
4 Deletes records.
DCL - Data Control Language
S.N. Command & Description
GRANT
Gives a privilege to user.
1
REVOKE
Takes back privileges granted from user.
2
GRANT AND REVOKE
Grant Privileges on Table
•You can grant users various
privileges to tables. These
permissions can be any combination
of SELECT, INSERT, UPDATE, DELETE,
REFERENCES, ALTER, or ALL.
Syntax
Privilege Description
SELECT Ability to perform SELECT statements on the table.
INSERT Ability to perform INSERT statements on the table.
UPDATE Ability to perform UPDATE statements on the table.
DELETE Ability to perform DELETE statements on the table.
REFERENCES Ability to create a constraint that refers to the table.
Ability to perform ALTER TABLE statements to change
ALTER
the table definition.
ALL does not grant all permissions for the table.
ALL Rather, it grants the ANSI-92 permissions which are
SELECT, INSERT, UPDATE, DELETE, and REFERENCES.
Object
• The database object that you are granting permissions for. In
the case of granting privileges on a table, this would be the
table name.
User
• The name of the user that will be granted these privileges.
Example
• if you wanted to grant SELECT, INSERT, UPDATE, and DELETE
privileges on a table restaurant to a user name Michael, The
SQL GRANT statement is:
• GRANT SELECT, INSERT, UPDATE, DELETE ON restaurant TO
Michael;
• You can also use ALL keyword to indicate
that you wish to grant the ANSI-92
permissions (ie: SELECT, INSERT, UPDATE,
DELETE, and REFERENCES) to a user
named aliyu.
Example:
• GRANT ALL ON restaurant TO aliyu;
Revoke Privileges on Table
Privilege Description
SELECT Ability to perform SELECT statements on the table.
INSERT Ability to perform INSERT statements on the table.
UPDATE Ability to perform UPDATE statements on the table.
DELETE Ability to perform DELETE statements on the table.
REFERENCES Ability to create a constraint that refers to the table.
Ability to perform ALTER TABLE statements to change
ALTER
the table definition.
ALL does not revoke all permissions for the table.
ALL Rather, it revokes the ANSI-92 permissions which are
SELECT, INSERT, UPDATE, DELETE, and REFERENCES.
Object
• The name of the database object that you are revoking privileges for.
User
The name of the user that have these privileges.
Examples.
• If you wanted to revoke DELETE privileges on a table
called employee from a user named anderson, the REVOKE statement
is:
REVOKE DELETE ON employee FROM anderson;
• If you wanted to revoke ALL ANSI-92 permissions (ie: SELECT, INSERT,
UPDATE, DELETE, and REFERENCES) on a table for a user named anderson,
you could use the ALL keyword as follows:
• The INNER JOIN keyword selects records that have matching values in
both tables.
Order Table
Customer Table
2 Ana Trujillo Emparedados y Ana Trujillo Avda. de la Constitución México D.F. 05021 Mexico
helados 2222
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
The following SQL statement selects
all orders with customer
information:
2 Ana Trujillo Emparedados y Ana Trujillo Avda. de la Constitución México D.F. 05021 Mexico
helados 2222
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
Order Table
Example
SELECT Customers.CustomerName,
Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID =
Orders.CustomerID
ORDER BY Customers.CustomerName;
Result
RIGHT JOIN Keyword
• The RIGHT JOIN keyword returns all records from the right table
(table2), and the matching records (if any) from the left table (table1).
Order Table
Employee Table
2 Ana Trujillo Ana Trujillo Avda. de la Constitución México D.F. 05021 Mexico
Emparedados y 2222
helados
3 Antonio Moreno Antonio Mataderos 2312 México D.F. 05023 Mexico
Taquería Moreno
Order table:
• If you add a WHERE clause (if table1 and table2 has a relationship),
the CROSS JOIN will produce the same result as the INNER JOIN clause:
Example
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
CROSS JOIN Orders
WHERE Customers.CustomerID=Orders.CustomerID;
The Result is
Database Security
• Database security includes a variety of measures
used to secure database management systems
from malicious cyber-attacks and illegitimate use.
• Database security programs are designed to
protect not only the data within the database, but
also the data management system itself, and every
application that accesses it, from misuse, damage,
and intrusion.
Database Security Threats
•Many software vulnerabilities,
loophole, misconfigurations or
carelessness could result in
breaches.
•Example of the most known causes
and types of database security
cyber threats.
Insider Threats
An insider threat is a security risk from one of the following
three sources, each of which has privileged means of entry to
the database:
• A malicious insider with ill-intent (industrial espionage)
• A negligent person within the organization who exposes the
database to attack through careless actions
• An outsider who obtains credentials through
social engineering and gains access to the database’s
credentials
An insider threat is one of the most typical causes of database security breaches
and it often occurs because a lot of employees have been granted privileged user
access.
Human Error
• Weak passwords, password sharing, accidental erasure or
corruption of data etc. are causes of almost half of
data breaches .
Exploitation of Database Software Vulnerabilities
Attackers constantly attempt to target vulnerabilities and
database management software is a highly valuable target.
New vulnerabilities are discovered daily, open source and
commercial database software vendors issue security patches
regularly. However, if you don’t use these patches quickly,
your database might be exposed to attack.
• Even if you do apply patches on time, there is always the risk of zero-day attacks, when attackers
discover a vulnerability, but it has not yet been discovered and patched by the database vendor.
SQL/NoSQL Injection Attacks
• A database-specific threat involves the use of arbitrary/random
non-SQL and SQL attack strings into database queries.
• Typically, these are queries created as an extension of web
application forms. Any database system is vulnerable to these
attacks, if organization does not carry out regular vulnerability
testing.
Buffer Overflow Attacks
• Buffer overflow takes place when a process tries to write a
large amount of data to a fixed-length block of memory, more
than it is permitted to hold. Attackers might use the excess
data, kept in adjacent memory addresses, as the starting point
from which to launch attacks.
Denial of Service (DoS/DDoS) Attacks
• In (DoS) attack, the cybercriminal overwhelms the target which
is the database server—using a large amount of fake requests.
The result is that the server cannot carry out genuine requests
from actual users, and often crashes or becomes unstable.
Malware/spyware
• Malware is software written to take advantage of vulnerabilities
to cause harm to a database. Malware could arrive through any
endpoint device connected to the database’s network. Malware
protection is important on any endpoint, especially on database
servers, because of their high value and sensitivity.
An Evolving IT Environment
• The evolving IT environment is making databases more
susceptible to threats. Here are trends that can lead to new
types of attacks on databases:
• Growing data volumes—storage, data capture, and
processing is growing exponentially across almost all
organizations.
• Distributed infrastructure—network environments are
increasing in complexity, especially as businesses transfer
workloads to hybrid cloud or multi-cloud architectures,
making the deployment, management, and choice of
security solutions more difficult.
• Increasingly tight regulatory requirements—the
worldwide regulatory compliance landscape is
growing in complexity, so following all mandates
are becoming more challenging.
• Cybersecurity skills shortage—there is a global
shortage of skilled cybersecurity professionals,
and organizations are finding it difficult to fill
security roles. This can make it more difficult to
defend critical infrastructure, including
databases.
How Can You Secure Your Database Server?