SQL for dummies
Tags: sql, beginners, database, mysql
Published: 2020-05-10 19:56:24

<p>SQL is a structured query language through which it is
possible to access, manage and retrieve data contained in a relational
database, including the creation of databases, the deletion and recovery of
rows or the modification of these, etc. SQL is an ANSI (American National
Standards Institute) standard language, although there are multiple versions of
this language.</p>

<p>SQL is the standard computer language used in relational
database management systems (RDMS) such as MySQL, MS Access, Oracle, Sybase,
Informix, Postgres and SQL Server. </p>

<h2>SQL Functionalities</h2>

<p>SQL is one of the most widely used query languages in
relational database management because of the utilities it offers users:</p>

<ul>
<li> access to data contained in relational databases,  </li>

<li> the description of the data, </li>

<li> defining the data within a database, </li>

<li> the manipulation of these, </li>

<li> embedding in other languages through the use of SQL
modules, libraries and pre-compilers </li>

<li> the creation of databases and tables, </li>

<li> the **[views, procedures and functions](https://www.coursera.org/account/accomplishments/verify/SF9MPC4NSUQL?utm_campaign=sharing_cta&utm_content=cert_image&utm_medium=certificate&utm_product=course&utm_source=link)**, </li>

<li> establish permissions on tables, procedures and views.</li>

<li> Among other functionalities.</li>
</ul>

<h2>Components involved in the SQL process</h2>

<p>When a SQL command is executed for an RDBMS, the system
determines the best way to process that request, while the SQL engine
determines how to interpret that command.</p>

<p>Among the components involved in this process are the query
dispatcher, optimization engines, the classic query engine, the SQL query
engine, etc.</p>

<p>Note that the classic query engine handles non- SQL queries,
just as the SQL query engine does not handle logical files.</p>

<h2>Main SQL commands</h2>

<p>The main standard SQL commands with which to interact with
relational databases are CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These
commands are classified in groups according to their typology.</p>

<h2>RDBMS - relational database management system </h2>

<p>DBMS - database management system </p>

<p>RDBMS - Relational Database Management System</p>

<p>The Relational Database Management System, known as RDBMS,
is a database management system (DBMS) based on Edgar Frank Codd's relational
model. On this relational model the ANSI and ISO standards of the management
language, definition and manipulation of the SQL relational databases have been
defined. It is the basis of SQL and other database systems such as MS SQL
Server, Oracle, MySQL or Microsoft Access.</p>

<h2>Parts of a table in SQL</h2>

<h3>Explaining what a table is in SQL</h3>

<p>In a relational database management system, data is stored
in database objects called tables, which collect multiple data entries and
consist of numerous rows and columns.</p>

<p>The table is the simplest and most widely used form of data
storage within a relational database. </p>

<h3>Explaining what a field is in SQL</h3>

<p>Each of the SQL tables are divided into fields or columns
within a table, designed to contain information specific to each record in the
corresponding table.</p>

<h3>Explaining what a record or row is in SQL</h3>

<p>A record is a horizontal entity in a table. Each individual
entry in a table is a data row. </p>

<h3>Explaining what a column is in SQL</h3>

<p>A column is a vertical entity in a table, which contains
information related to a specific field within the table.</p>

<h3>Explaining what a NULL value is in SQL</h3>

<p>A field with a NULL value is a field that is left blank
during the creation of a record. In a table, a NULL value represents a field
with no value, other than a zero value or a field with spaces. </p>

<h2>Constraints in SQL</h2>

<p>When we talk about constraints in SQL, we refer to the rules
that have been defined for the data columns in a table. These constraints are
used to limit the type of data that a table can contain, guaranteeing the
reliability of the data.</p>

<p>These restrictions can be defined at column or table level,
applying only to one column in the first case and to the whole table if it is
the second case. </p>

<p>Some of the most common restrictions you can find in SQL are</p>

<ul>
<li>NOT NULL constraint (makes a column unable to contain a NULL
value)</li>

<li>DEFAULT restriction (assigns a default value to a column
when one is not specified)</li>

<li>Single restriction (makes the values of one column
different)</li>

<li>PRIMARY KEY (makes the identification of each row or record
unique within a database table)</li>

<li>Foreign key (makes the identification of each row or record
unique in any other database table)</li>

<li>Checking restriction (ensures that the values in a column
meet specific conditions)</li>
</ul>

<h2>Categories of Data Integrity in SQL</h2>

<p>The data integrity categories of each RDBMS are:</p>

<p>- Entity integrity (no duplicate rows in a table)</p>

<p>- Domain integrity (restricts the type, format, and value
range that applies to valid entries for a column within a table)</p>

<p>- **[Referential integrity](https://www.linkedin.com/in/yel-martinez-informatica-seo-desarrollo-web-posicionamiento-buscadores/details/recommendations/)** (makes rows in a table that are
being used by other records impossible to delete)</p>

<p>- User-defined integrity (other specific rules not included
above apply)</p>

<h2>Standardization of a SQL database</h2>

<p>Standardization of a SQL database consists of a series of
guidelines established as a guide for the optimal creation of a database
structure.</p>

<p>SQL database normalization is the process of organizing data
in a database efficiently, eliminating duplicate data and ensuring that data
dependencies make sense. Normalization seeks to reduce the amount of space used
in a database and ensure that data is stored in a logical manner. </p>

<h2>Basic SQL Syntax</h2>

<p>A syntax is a unique set of rules and guidelines. In [SQL,
the syntax](https://www.credly.com/badges/b0809aba-1bde-43fb-aa29-7815fdef90a2) states that all declarations start with one of the keywords SELECT,
INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and end with a
semicolon.</p>

<p>It is important to note that SQL is not case sensitive in
SQL declarations, while MySQL is case sensitive in table names, so you will
need to handle the table names as defined in the database.</p>

<h2>SQL data types</h2>

<p>In SQL, the attributes that specify the type of data an
object will contain are known as the SQL Data Type.</p>

<p>Each column, variable, and expression has a related data
type. These can be used when creating tables by choosing the data type to be
used for a table column.</p>

<p>These data types are divided into six categories in SQL
Server</p>
<h3>data types categories</h3>

<p>- Exact numerical data types</p>

<p>- Types of approximate numerical data</p>

<p>- Types of date and time data</p>

<p>- Character string data types</p>

<p>- Unicode string data types</p>

<p>- Binary data types</p>

<p>- Various types of data</p>

<h2>The SQL operators</h2>

<p>In SQL, when we speak of operators, we refer to reserved
words or characters, used mainly in the WHERE clause of a SQL statement, in
order to carry out arithmetic operations, comparisons, etc. </p>

<p>These operators are used to specify conditions within a SQL
statement. </p>

<p>Types of SQL operators include arithmetic operators,
comparison operators, and logical operators.</p>