Professional Documents
Culture Documents
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This ensures
the accuracy and reliability of the data in the table. If there is any violation
between the constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to a
column, and table level constraints apply to the whole table.
The following constraints are commonly used in SQL:
NOT NULL - Ensures that a column cannot have a NULL value
UNIQUE - Ensures that all values in a column are different
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies
each row in a table
FOREIGN KEY - Uniquely identifies a row/record in another table
CHECK - Ensures that all values in a column satisfies a specific condition
DEFAULT - Sets a default value for a column when no value is specified
INDEX - Used to create and retrieve data from the database very quickly
SQL table structure
7
Example
Features:
The NOT NULL specifications for the attributes ensure that a data entry
will be made.
The UNIQUE specification creates a unique index in the respective attribute.
Use it to avoid duplicated values in a column.
The primary key attributes contain both a NOT NULL and a UNIQUE
specification.
RDBMS will automatically enforce referential integrity for foreign keys
The entire table definition is enclosed in parentheses. A comma is used to
separate each table element (attributes, primary key, and foreign key)
definition.
The command sequence ends with a semicolon
9
and constraints
Table and attribute names are capitalized
SQL data definition commands
10
1. Create table
used to specify a new relation by giving it a name
Example
2. Alter table
All changes in table structure are made by using ALTER
command
Three options:
3. Drop table
A table can be deleted from the database using the
DROP TABLE command
Example
A. INSERT
B. SELECT
C. ORDER BY
D. GROUP BY
E. HAVING
F. WHERE
G. UPDATE
H. DELETE
I. COMMIT
J. ROLLBACK
INSERT
SELECT
COMMIT
UPDATE
ROLLBACK
DELETE
INSERT
Used to enter data into table
Syntax:
INSERTINTO columnname
VALUES (value1, value2, … , valueN);
Example
SELECT
Syntax:
USING ALIASES
USING PARENTHESES
Example
Group By
31
Examples
NVL FUNCTION
FORCES GROUP
FUNCTION TO INCLUDE
NULL VALUES
Example:
Example:
Example
Commit
39
Syntax:
COMMIT [WORK];
Will permanently save any changes made to any
table in the database
MySQL:
Autocommit
Rollback
40
ROLLBACK
Undoes changes since last COMMIT
Brings data back to prechange values
Syntax:
ROLLBACK;
Example:
Arithmetic Operators:
43
The Rule of Precedence
Perform operations within parentheses
Perform power operations
Perform multiplications and divisions
Perform additions and subtractions
Examples:
Example
54
Airtable is cloud-based database software that comes with features such as data
tables for capturing and displaying information, user permissions for managing the
database, and file storage and sharing capabilities with document history tracking.
The tool can also be used to manage and track tasks using its kanban dashboards,
built-in calendars, and spreadsheets.
Pros: Users mention that the tool is
easy to get started with due to its
pre-built database templates for
different business purposes, such as
lead management, bug tracking, and
applicant tracking.
GraphDB is a graphical database that comes with both cloud and on-premise
deployment options. It offers features such as data repositories, textual analytics,
and knowledge graphs.
The tool can be used to tag and analyze textual data semantically based on
keywords and topics or concepts. The tagged data can then be visualized as
knowledge graphs to search and find relationships between disparate data.
MariaDB is an open source relational database for data storage, data insertion into
tables, data modifications, and data retrieval. As an open source solution, the tool is
free to use and you can get started by downloading the software on your desktop
or laptop.
PostgreSQL is an open source database that comes with features such as data
indexing, user configuration settings, data import/export, and version control.
While PostgreSQL is a relational database, it also allows creating NoSQL
databases with programming languages such as Python and JSON.
Sonadier is cloud-based solution for creating databases and web forms. The tool
comes with features such as form generation through a drag-and-drop interface,
file management, user data sharing permissions, data import/export, and data
versioning.
This is one of the most popular relational database systems. Originally an open-
source solution, MySQL now is owned by Oracle Corporation. Today, MySQL is a
pillar of LAMP application software. That means it’s a part of Linux, Apache,
MySQL, and Perl/PHP/Python stack. Having C and C++ under the hood, MySQL
works well with such system platforms as Windows, Linux, MacOS, IRIX, and others.
Pros of MySQL
Free installation.
Simple syntax and mild
complexity.
Cloud-compatible.
Cons of MySQL
Scalability challenges.
Partial open source.
Limited compliance with SQL
standards.
Joining Database Tables
65
Example:
STAFF