<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Database Journal</title>
	<atom:link href="https://www.databasejournal.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.databasejournal.com/</link>
	<description></description>
	<lastBuildDate>Tue, 11 Mar 2025 16:26:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>
	<item>
		<title>SQL SORT BY Statement</title>
		<link>https://www.databasejournal.com/features/sql-sort-by-statement/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Tue, 21 Mar 2023 02:11:32 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[database administrator]]></category>
		<category><![CDATA[database development]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[SORT BY]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL syntax]]></category>
		<category><![CDATA[syntax]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16837</guid>

					<description><![CDATA[<p>In relational databases, the SQL ORDER BY statement is a powerful tool for sorting data in a table. The statement is used to arrange queried data into rows in a specific order, based upon one or more columns. In this database programming tutorial, we will learn how to use the SQL ORDER BY statement to [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-sort-by-statement/">SQL SORT BY Statement</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignnone size-medium wp-image-16721" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>In relational databases, the SQL <b>ORDER BY</b> statement is a powerful tool for sorting data in a table. The statement is used to arrange queried data into rows in a specific order, based upon one or more columns. In this database programming tutorial, we will learn how to use the SQL <b>ORDER BY</b> statement to sort retrieved data in <i>ascending</i> or <i>descending</i> order.</p>
<p><b>Read:</b> <a href="https://www.databasejournal.com/features/database-administrator-courses/" target="_blank" rel="noopener">Best Courses for Database Administrators</a></p>
<h2>SQL ORDER BY Statement Syntax</h2>
<p>The syntax for the SQL <b>ORDER BY</b> statement is shown in the following example code:</p>
<pre>SELECT columnA, columnB, columnC
FROM table_example
ORDER BY columnA, columnB, columnC ASC|DESC;
</pre>
<p>In the example code above, the <b>SELECT</b> statement is used to first select the columns to be displayed from a given table. Then, the <b>FROM</b> statement defines the table name the data will be pulled from. The <b>ORDER BY</b> statement then sorts the retrieved data in either ascending or descending order, based on one (or more) columns.</p>
<p>They keywords <b>ASC</b> and <b>DESC</b> are optional parameters of <b>ORDER BY</b>, which dictate the order of the sort. <b>ASC</b> &#8211; which is short for <i>ascending</i> &#8211; is the default sort order, while DESC &#8211; which is short for <i>descending</i> &#8211; sorts the data in the reverse order.</p>
<h2>How to Sort Data in Ascending Order in SQL</h2>
<p>In SQL databases, database developers can sort data in ascending order using the SQL <b>ORDER BY</b> statement and the optional parameter (discussed above) <b>ASC</b>, alongside the column (or columns) you want to sort by.</p>
<p>For instance, if a programmer or database administrator has a table named <b>employees</b> that has the columns: <b>employee_id</b>, <b>first_name</b> <b>last_name</b>, and <b>hire_date</b>. If we wanted to sort the queried data by ascending order by the <b>last_name</b> column, we could use the following example SQL query:</p>
<pre>SELECT * FROM employees
ORDER BY last_name ASC;
</pre>
<p>The above query chooses every column from the <b>employees</b> table. It then sorts the data in ascending order by the <b>last_name</b> column.</p>
<h2>How to Sort Data in Descending Order in SQL</h2>
<p>Sorting data in descending order in SQL is possible as well, also using the SQL <b>ORDER BY</b> statement. All database developers need to do is add the <b>DESC</b> keyword after the column (or columns) you intend to sort by. As an example, if you want to sort the <b>employees</b> table by descending order using the <b>last_name</b> column, you would use the following SQL query:</p>
<pre>SELECT * FROM employees
ORDER BY last_name DESC;
</pre>
<p>The above query retrieves all columns from the <b>employees</b> table and then sorts the data by <b>last_name</b> in descending order.</p>
<h2>How to Sort by Multiple Columns in SQL Using ORDER BY</h2>
<p>Database administrators and database programmers can also sort by multiple columns using the SQL <b>ORDER BY</b> statement. To do this, all you need to do is note which columns you want to sort by in the <b>ORDER BY</b> clause, using commas as separators. The retrieved data gets sorted <i>first</i> by the first column, and <i>then</i> using the second column. If there are more than two sort clauses, the sort continues in order as expected. For instance, if we wanted to sort our <b>employees</b> table by the <b>last_name</b> column, and <i>then</i> using the <b>first_name</b> column, we would use the SQL query below:</p>
<pre>SELECT * FROM employees
ORDER BY last_name ASC, first_name ASC;
</pre>
<p>The above SQL query retrieves every column from the <b>employees</b> table and then sorts the information by ascending order using the <b>last_name</b> column. In cases where more than one employee has the same last name, then the returned data will then be sorted in ascending order by the <b>first_name</b> column.</p>
<p><b>Read:</b> <a href="https://www.databasejournal.com/features/project-management-software-database/" target="_blank" rel="noopener">Project Management Software for Database Developers</a></p>
<h2>How to Sort Data by Calculated Columns in SQL</h2>
<p>Database developers and db admins can also sort data by columns in a table using calculated columns. Calculated columns are columns that are created when we use a calculation or equation on one or more existing columns in a table. For example, in our table <b>employees</b> if we wanted to sort by the sum of the <b>salary</b> and <b>bonus</b> columns, in ascending order, we could use the following SQL query:</p>
<pre>SELECT *, salary + bonus as total_income FROM employees
ORDER BY total_income ASC;
</pre>
<p>The above SQL query chooses all columns from the <b>employees</b> table and then creates a <i>calculated</i> column named <b>total_income</b> by using the sum of <b>salary</b> and <b>bonus</b>. The returned data is then sorted in ascending order courtesy of the <b>total_income</b> column.</p>
<h2>How to Sort Data by Alias Names in SQL with ORDER BY</h2>
<p>There are some instances where database programmers might need to sort data using an <i>alias name</i> that we define in our <b>SELECT</b> statement. To achieve this, put the alias name in the <b>ORDER BY</b> clause.</p>
<p>As an example, using our <b>employee</b> table let’s say we wanted to sort our data using a <b>total_income</b> table we set as an alias name, by descending order, we can use the following SQL query and statement:</p>
<pre>SELECT *, salary + bonus as total_income FROM employees
ORDER BY total_income DESC;
</pre>
<p>Our example query works by selecting every column from our <b>employees</b> table and creates a new calculated column named <b>total_income</b> (our alias named column) by adding together the <b>salary</b> and <b>bonus</b> columns. This data is then sorted in descending order using our new <b>total_income</b> column.</p>
<h2>Sorting Data by NULL Values</h2>
<p>Sometimes you need to sort data in a relational database that contains a <b>NULL</b> value; querying this sort of data can cause problems if the database developer does not account for this possibility. The reason for this is that <b>NULL</b> is not technically a value, but, instead, a placeholder representing the <i>absence</i> of a value. If you are sorting data containing <b>NULL</b>, they are typically sorted at either the <i>beginning</i> or <i>end</i> of the results, depending on how you set the sort order.</p>
<p>Developers can specify where NULL values are sorted using the <b>NULLS FIRST</b> or <b>NULLS LAST</b> keywords in the <b>ORDER BY</b> clause. Let’s say you wanted to sort the <b>employees&#8221;</b> table in ascending order using the <b>manager_id</b> column, with <b>NULL</b> values sorted last. To do so, we could use the following SQL query:</p>
<pre>SELECT * FROM employees
ORDER BY manager_id ASC NULLS LAST;
</pre>
<p>The query above selects all columns from the <b>employees</b> table, then sorts the data in ascending order by the <b>manager_id</b> column, sorting the <b>NULL</b> values last.</p>
<p>You can learn more about <b>NULL</b> values in our tutorial: <a href="https://www.databasejournal.com/features/sql-null-values/" target="_blank" rel="noopener">Working with NULL Values in SQL</a>.</p>
<h2>Final Thoughts on SQL ORDER BY</h2>
<p>The SQL <b>ORDER BY</b> statement is used to sort data in a relational database. Using it, database developers and database administrators can sort data in ascending or descending order, using one or more columns, calculated columns, or alias names. You can also specify where <b>NULL</b> values should be sorted in the results, avoiding some common query errors caused by <b>NULL</b> values. Understanding how to use the <b>ORDER BY</b> statement in SQL lets programmers and admins manipulate data to create more robust queries and make your relational database more efficient.</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-sort-by-statement/">SQL SORT BY Statement</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Working with NULL Values in SQL</title>
		<link>https://www.databasejournal.com/features/sql-null-values/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Thu, 09 Mar 2023 17:17:30 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[cheat sheet]]></category>
		<category><![CDATA[data type]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[database administrator]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[relational database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL syntax]]></category>
		<category><![CDATA[syntax]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16832</guid>

					<description><![CDATA[<p>In SQL and relational databases, NULL values are an important part of managing data and information stored in SQL tables. A NULL value is used as a placeholder for missing values or values that are unknown in a database column or cell. Understanding how to handle NULL values is important for database developers who want [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-null-values/">Working with NULL Values in SQL</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignnone size-medium wp-image-16721" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="(max-width: 300px) 100vw, 300px" /><br />
In SQL and relational databases, <b>NULL</b> values are an important part of managing data and information stored in SQL tables. A <b>NULL</b> value is used as a placeholder for missing values or values that are unknown in a database column or cell. Understanding how to handle <b>NULL</b> values is important for database developers who want to avoid errors and retrieve accurate results when querying a database table. This database development tutorial covers the basics of how to work with NULL values in SQL.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn SQL</a></p>
<h2>What is a NULL Value in SQL?</h2>
<p>In relational databases and RDBMS’, <b>NULL</b> values are a special value in SQL that are used to represent an unknown &#8211; or in some instances, a missing &#8211; value in a column or cell. A lot of newer database developers think that NULL is the same as a zero value integer or an empty string; however, in reality <b>NULL</b> is a value representing the <i>absence</i> of any value. You should note that <b>NULL</b> values are not equal to any other value, including other <b>NULL</b> values.</p>
<p>For database administrators and programmers working with <b>NULL</b> values in SQL, it is important to understand how this unique value is handled in different situations. For instance, when performing mathematical calculations, NULL values <i>always</i> return a <b>NULL</b> value. Because of this, we need to handle <b>NULL</b> values properly in order to avoid errors in calculations and our SQL queries.</p>
<h2>How to Create a Table with NULL Values in SQL</h2>
<p>To create a table in SQL, you first specify which columns will allow <b>NULL</b> values. By default, every column will allow <b>NULL</b> values unless programmers say otherwise.</p>
<p>The SQL syntax and statement below shows how to create a table containing <b>NULL</b> values:</p>
<pre>CREATE TABLE employees (
  id INT PRIMARY KEY,
  first_name VARCHAR(50),
  last_name VARCHAR(50),
  email VARCHAR(100),
  phone_number VARCHAR(20) NULL,
  hire_date DATE,
  job_id INT,
  salary DECIMAL(10,2) NULL,
  commission_pct DECIMAL(4,2) NULL,
  manager_id INT NULL,
  department_id INT
);
</pre>
<p>In the above code example, we created an <b>employees</b> table with several columns. The <b>phone_number</b>, <b>salary</b>, <b>commission_pct</b>, and <b>manager_id</b> columns can contain <b>NULL</b> values. This is achieved using the <b>NULL</b> keyword.</p>
<h2>How to Insert NULL Values into a Table in SQL</h2>
<p>You can insert <b>NULL</b> values into a table that allows <b>NULL</b> types by using the <b>NULL</b> keyword. Optionally, you can omit the value altogether to achieve the same result.</p>
<p>For instance, if we want to insert a <b>NULL</b> value into the <b>phone_number</b> column of the <b>employees</b> table from our previous example, we would use the following SQL syntax:</p>
<pre>INSERT INTO employees (id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct, manager_id, department_id)
VALUES (1, 'John', 'Doe', 'johndoe@email.com', NULL, '2023-01-01', 1, 5000.00, 0.10, NULL, 1);
</pre>
<p>Here, In this SQL example, we inserted a new employee into the <b>employees</b> table. The <b>phone_number</b> and <b>manager_id</b> columns both contain <b>NULL</b> values.</p>
<h2>How to Query NULL Values in SQL</h2>
<p>If we query data in a relational database that contains <b>NULL</b> values, we must first understand how they are handled in different situations.</p>
<p>For instance, if we want to query data that contains <b>NULL</b> values, we can use the <b>IS NULL</b> or <b>IS NOT NULL</b> keywords. Let’s say we want to select every employee from the <b>employees</b> table who do not have a phone number; in this instance, we would would use the following SQL query:</p>
<pre>SELECT * FROM employees
WHERE phone_number IS NULL;
</pre>
<p>In the above example, we selected every column from the <b>employees</b> table where the <b>phone_number</b> column contains a <b>NULL</b> value.</p>
<p>Another way to use <b>NULL</b> values in SQL is to retrieve data where a specific record <i>is not</i> <b>NULL</b>. For instance, if we want to select every employee from the <b>employees</b> table who have a phone number, you could use the following SQL query:</p>
<pre>SELECT * FROM employees
WHERE phone_number IS NOT NULL;
</pre>
<p>In this SQL example, we selected all values from the <b>employees</b> table where the <b>phone_number</b> column <i>is not</i> <b>NULL</b>.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-data-types/" target="_blank" rel="noopener">SQL Data Types</a></p>
<h2>Using SQL NULL Values in Calculations</h2>
<p>If you add a <b>NULL</b> value to a numeric value, the result is always <b>NULL</b>. The same goes for any mathematical operation involving a <b>NULL</b> value. Because of this, it is important for database programmers to use the <b>IS NULL</b> keyword to check for <b>NULL</b> values before performing any mathematical operations in SQL or relational databases.</p>
<p>As an example, if we wanted to calculate the average salary of every employee in our <b>employees</b> table, we could use the SQL query below:</p>
<pre>SELECT AVG(salary) AS average_salary
FROM employees
WHERE salary IS NOT NULL;
</pre>
<p>In this query, we used the <b>AVG</b> function to calculate the average salary of every employee. Additionally, we used the <b>IS NOT NULL</b> keyword to exclude any employees that have no salary.</p>
<h2>SQL COALESCE Function</h2>
<p>In SQL, the <b>COALESCE</b> function is used to handle <b>NULL</b> values in SQL. The <b>COALESCE</b> function takes multiple arguments and returns the first <b>non-NULL</b> value. This function is used to replace <b>NULL</b> values with a default value, or if you want to prioritize one value over another.</p>
<p>If we wanted to select the salary of an employee and replace any NULL values in the table with a default value of <b>0</b>, we could use the following SQL query:</p>
<pre>SELECT COALESCE(salary, 0) AS salary
FROM employees;
</pre>
<p>Here, we used the <b>COALESCE</b> function to retrieve the salary column of the <b>employees</b> table. If the value representing salary is <b>NULL</b>, the function will return a default value of <b>0</b>.</p>
<h2>How to Use the IFNULL Function</h2>
<p>The SQL <b>IFNULL</b> function works similar to the <b>COALESCE</b> function, but it only takes two arguments. The <b>IFNULL</b> function returns the first argument if it is <i>not</i> <b>NULL</b>; otherwise, the second argument is returned.</p>
<p>To retrieve the salary of an employee and replace all <b>NULL</b> values with a default value of <b>0</b>, the following SQL query can be used:</p>
<pre>SELECT IFNULL(salary, 0) AS salary
FROM employees;
</pre>
<p>This example uses the SQL <b>IFNULL</b> function to return the salary column of the <b>employees</b> table. If the salary is <b>NULL</b>, <b>IFNULL</b> returns a default value of <b>0</b>.</p>
<h2>Final Thoughts on SQL NULL Values</h2>
<p>In SQL, <b>NULL</b> values are important for managing data. <b>NULL</b> values are placeholders for missing or unknown values in a column. Understanding how to work with <b>NULL</b> values helps database developers avoid errors and create more accurate results with our queries.</p>
<p>Keep in mind that when you create a table in SQL, database programmers can specify which columns can allow <b>NULL</b> values. By default, all columns will allow <b>NULL</b> values unless otherwise specified. If you want to insert data into a table that allows <b>NULL</b> values, you can insert a <b>NULL</b> value using the <b>NULL</b> keyword. You can also simply omit the value as well.</p>
<p>If you query data that contains <b>NULL</b> values, programmers can use the <b>IS NULL</b> or <b>IS NOT NULL</b> SQL keywords to select data containing <b>NULL</b> values or if you want to exclude data that contains <b>NULL</b> values.</p>
<p>The SQL <b>COALESCE</b> and <b>IFNULL</b> functions are great for handling <b>NULL</b> values in SQL. The <b>COALESCE</b> function uses multiple arguments and returns the first <b>non-NULL</b> value, while the <b>IFNULL</b> function only takes two arguments and returns the first argument if it <i>is not</i> <b>NULL</b>. If not, it returns the second argument.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-best-practices/" target="_blank" rel="noopener">SQL Best Practices</a></p>
<p>The post <a href="https://www.databasejournal.com/features/sql-null-values/">Working with NULL Values in SQL</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Working with SQL AND, OR, and NOT Operators</title>
		<link>https://www.databasejournal.com/features/sql-and-or-not-operator/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Tue, 21 Feb 2023 03:17:43 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[AND]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database development]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[NOT]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[OR]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[syntax]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16767</guid>

					<description><![CDATA[<p>In a previous tutorial, we learned how to work with the WHERE clause in SQL, which database developers can use when they wish to retrieve a group of records that meet a certain criteria or condition. For instance, a database administrator may wish to find every instance in a database where a user’s name is [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-and-or-not-operator/">Working with SQL AND, OR, and NOT Operators</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignnone size-medium wp-image-16721" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>In a previous tutorial, we learned how to work with the <b>WHERE</b> clause in SQL, which database developers can use when they wish to retrieve a group of records that meet a certain criteria or condition. For instance, a database administrator may wish to find every instance in a database where a user’s name is equal to “Ronnie” &#8211; or, more likely, <i>not equal to</i> “Ronnie”. As powerful as the <b>WHERE</b> clause is in SQL, we can make it even stronger when we apply SQL’s <b>NOT</b>, <b>AND</b>, and <b>OR</b> operators.</p>
<p>This database development tutorial shows db admins and programmers how to use the <b>NOT</b>, <b>AND</b>, and <b>OR</b> operators in SQL, complete with syntax, code examples, and use cases.</p>
<p>Before we get started, however, you may wish to review our tutorial: <a href="https://www.databasejournal.com/features/sql-where-clause/" target="_blank" rel="noopener">How to Use the SQL WHERE Clause</a>.</p>
<h2>What is the AND Operator in SQL?</h2>
<p>The <b>AND</b> operator in SQL is used to display a given record if every condition separated by the <b>AND</b> operator are <b>TRUE</b>. It is used in conjunction with the <b>WHERE</b> clause to filter records based on two or more conditions.</p>
<h3>SQL AND Syntax</h3>
<p>The syntax for the <b>AND</b> operator in SQL is as follows:</p>
<pre>SELECT columnA, columnB
FROM table_example
WHERE conditionA and conditionB …;
</pre>
<h3>SQL AND Code Example</h3>
<p>For our SQL <b>AND</b> operator code example, let’s pretend we have a database named <b>Nakamura Industries</b> and within that database is a table named <b>employees</b>, which, as you can imagine, hold information pertaining to employee records. Let’s further posit that our table has the following columns:</p>
<ul>
<li><b>firstName</b>: Holds first name of employee</li>
<li><b>lastName:</b> Holds last name of employee</li>
<li><b>employeeID:</b> Holds unique number representing the employees ID number</li>
</ul>
<p>Let’s say that this table has the following information:</p>
<pre>firstName	lastName	employeeID
Ronnie	        Payne		001
Donnie	        Layne		002
Ronnie	        Donnie	003
</pre>
<h3>How to Use SQL AND to Retrieve a Record</h3>
<p>Using our sample table above, to retrieve a record from a database using SQL <b>AND</b>, we would write the following SQL query:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE firstName=”Ronnie” AND lastName=”Payne”;
</pre>
<p>In this example query, we are looking for an employee in the database whose first name is <b>Ronnie</b> and whose last name is <b>Payne</b>. If no record exists that meets <i>both</i> of those requirements, no records will be returned. Since we do, indeed, have a record where <i>both</i> sets of criteria are met, we get the result:</p>
<pre>Ronnie Payne 001
</pre>
<p>when we execute our query.</p>
<h4>Querying Multiple AND Criteria in SQL</h4>
<p>We can, of course, query for more than two sets of criteria in SQL using the <b>AND</b> operator. In those cases, every piece of criteria must be met. Here is an example showing a query where three conditions must be met:</p>
<pre>SELECT <strong>fiRead: rstName,</strong> lastName, employeeID
FROM employees
WHERE firstName=”Ronnie” AND lastName=”Payne” AND employeeID=007;
</pre>
<p>In this example SQL query, we are asking the database to return every record that has a first name of <b>Ronnie</b>, a last name of <b>Payne</b>, and an employee ID matching <b>007</b>.</p>
<p>Keen observers will note that the employee <b>Ronnie Payne</b> has an employee ID of <b>001</b>; since his employee ID is not <b>007</b> &#8211; and therefore not <i>all three</i> conditions are met, the query would return an empty result.</p>
<p>If we rewrote our SQL query to reflect the following, it would, instead, return the desired result:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE firstName=”Ronnie” AND lastName=”Payne” AND employeeID=001;
</pre>
<p>Using this updated SQL query and <b>AND</b> operator, we would get the following output:</p>
<pre>Ronnie Payne 001
</pre>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn SQL</a></p>
<h2>What is the SQL OR Operator?</h2>
<p>Like the SQL <b>AND</b> operator, the <b>OR</b> operator works in conjunction with the <b>WHERE</b> clause to query database tables for information where one <i>or</i> more conditions are <b>TRUE</b>.</p>
<p>Unlike with the <b>AND</b> operator, where <i>all</i> conditions must be <b>TRUE</b>, in scenarios where <b>OR</b> is used, only <i>one</i> condition must evaluate to <b>TRUE</b>.</p>
<h3>SQL OR Operator Syntax</h3>
<p>The syntax for SQL’s <b>OR</b> operator is as follows:</p>
<pre>SELECT columnA, columnB
FROM table_example
WHERE conditionA OR conditionB …;
</pre>
<h3>SQL OR Example Code</h3>
<p>In the following example, we will use the same example database from before, and this time, create a query where we are seeking <b>firstName</b> values that equal either <b>Ted</b> <i>or</i> <b>Larry</b>:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE firstName=”Ted” OR firstName=”Larry”;
</pre>
<p>Running the above SQL query will return no results, as table <b>employees</b> contains no <b>firstName</b> records containing <b>Ted</b> <i>or</i> <b>Larry</b>.</p>
<p>Consider this SQL example:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE firstName=”Ted” OR firstName=”Ronnie”;
</pre>
<p>In this example, we set our criteria to search the column <b>firstName</b> for <i>either</i> <b>Ted</b> <i>or</i> <b>Ronnie</b>. Since one of the <b>OR</b> operator’s criteria is met, we get the result:</p>
<pre>Ronnie Payne 001
Ronnie Donnie 003
</pre>
<h3>Using SQL OR to Query for Multiple Criteria</h3>
<p>Like the <b>AND</b> operator, database programmers and database administrators can use the <b>OR</b> operator to retrieve data from a table using multiple criteria. Here is an example of how to use the <b>OR</b> operator with the <b>WHERE</b> clause to query for data based on three sets of criteria:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE firstName=”Ted” OR firstName=”Ronnie” OR firstName=”Donnie”;
</pre>
<p>Here, we are looking for the value <b>Ronnie</b>, <b>Donnie</b>, <i>or</i> <b>Ted</b> &#8211; if <i>any</i> of that criteria is met, results will be returned. Below is the output of running this query:</p>
<pre>Ronnie	Payne		001
Donnie	Layne		002
Ronnie	Donnie	        003
</pre>
<h2>What is the SQL NOT Operator</h2>
<p>The SQL <b>NOT</b> operator can be a little confusing and take some time to get used to using properly. Instead of using it to find criteria that is <b>TRUE</b>, instead, database programmers use it to find data where a set of criteria is <b>NOT TRUE</b>, which is technically different than <b>FALSE</b>.</p>
<p>Because there are values that are equal to <b>null</b> in SQL, the <b>NOT</b> operator is sometimes used so query databases. The value <b>null</b> is neither <b>TRUE</b> nor <b>FALSE</b> &#8211; also known as not <b>0</b> <i>or</i> <b>1</b>. So if you wanted to query a table that had <b>null</b> values in it, you could use the <b>NOT</b> operator to find such values.</p>
<h3>SQL NOT Operator Syntax</h3>
<p>Below if the syntax for using the <b>NOT</b> operator in SQL queries:</p>
<pre>SELECT columnA, columnB
FROM table_example
WHERE NOT conditionA …;
</pre>
<h3>SQL NOT Operator Code Example</h3>
<p>Of course, the SQL <b>NOT</b> operator can also simply retrieve values from a table that are not equal to <b>TRUE</b> as well. Consider the following example SQL query:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE NOT firstName=”Ronnie”;
</pre>
<p>In the above example, we are specifically looking for records that do not contain <b>Ronnie</b> (or, put another way, where the value of <b>firstName</b> is not equal to <b>Ronnie</b>). Since there are two records in <b>firstName</b> that contain the value <b>Ronnie</b> &#8211; or the employees <b>Ronnie Payne</b> and <b>Ronnie Donnie</b> &#8211; the query will return the results that <i>do not</i> contain those values.</p>
<p>Here would be the output of running the above query:</p>
<pre>Donnie	Layne		002
</pre>
<h2>SQL Operators: NOT, AND, OR Used Together</h2>
<p>Finally, it is plausible to use an SQL <b>WHERE</b> clause that used the <b>AND</b>, <b>OR</b>, <i>and</i> <b>NOT</b> in the same statement:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE firstName=”Ronnie” AND lastName=”Payne” OR lastName=”Donnie”;
</pre>
<p>Similarly, you can combine <b>NOT</b> with <b>AND</b> or <b>OR</b> operators too:</p>
<pre>SELECT firstName, lastName, employeeID
FROM employees
WHERE NOT firstName=”Ronnie” AND NOT lastName=”Payne” OR lastName=”Donnie”;
</pre>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/ms-sql/database-administrator-courses/" target="_blank" rel="noopener">Best Courses for Database Administrators</a></p>
<p>The post <a href="https://www.databasejournal.com/features/sql-and-or-not-operator/">Working with SQL AND, OR, and NOT Operators</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Use Databases With Python</title>
		<link>https://www.databasejournal.com/features/python-databases/</link>
		
		<dc:creator><![CDATA[technologyadv]]></dc:creator>
		<pubDate>Fri, 10 Feb 2023 04:34:07 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[close()]]></category>
		<category><![CDATA[COMMIT]]></category>
		<category><![CDATA[connect()]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database development]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[execute]]></category>
		<category><![CDATA[MySQLConnection]]></category>
		<category><![CDATA[MySQLCursor]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Python3]]></category>
		<category><![CDATA[software development]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16759</guid>

					<description><![CDATA[<p>Python allows developers to interact with various relational databases (such as Oracle, SQLite, and MySQL) and relational database systems (RDBMS) through several different libraries, which must conform to standards defined in PEP 249. In this database programming tutorial, we will discuss how to connect to a MySQL database using Python and make database queries. You [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/python-databases/">How to Use Databases With Python</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-16646" src="https://assets.databasejournal.com/uploads/2010/05/MySQL-icon..jpeg" alt="MySQL tutorials" width="200" height="200" srcset="https://assets.databasejournal.com/uploads/2010/05/MySQL-icon..jpeg 200w, https://assets.databasejournal.com/uploads/2010/05/MySQL-icon.-150x150.jpeg 150w" sizes="auto, (max-width: 200px) 100vw, 200px" /></p>
<p>Python allows developers to interact with various relational databases (such as Oracle, SQLite, and MySQL) and relational database systems (RDBMS) through several different libraries, which must conform to standards defined in PEP 249.</p>
<p>In this database programming tutorial, we will discuss how to connect to a MySQL database using Python and make database queries. You can read more about the PEP 249 by visiting the <a href="https://peps.python.org/pep-0249/" target="_blank" rel="noopener">Python Database API Specification</a>.</p>
<h2>How to Create a Database Connection in Python</h2>
<p>To create a connection to a MySQL database in Python, developers first need to download a <i>database connector</i>, which is a module that will enable your Python scripts to interact with data. This tutorial will be using the MySQL database since it is one of the most popular and widely used databases.</p>
<p>Not familiar with MySQL or want to increase your MySQL development skills? We have a list of the <a href="https://www.databasejournal.com/features/mysql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn MySQL</a> to help get you started.</p>
<p>To download the Python MySQL database connector, you can use <b>PIP</b> with the following command:</p>
<pre>$ pip install mysql-connector-python
</pre>
<p>There are a number of other modules programmers can use to make database connections, such as <b>PyMySQL</b>, <b>MySqlClient</b>, and <b>OurSQL</b>. However, this programming tutorial uses the <b><b>MySQL Python</b> connector</b>, which is officially supported by Oracle and is written purely in Python.</p>
<p>To begin working with this module, you will need to import it into your script using the following command:</p>
<pre>import mysql.connector
</pre>
<p>Next, you need to create a connection to the database. There are two ways of doing this: you can either use the <b>connect()</b> function or use the <b>MySQLConnection</b> object.</p>
<h2>How to Use the connect() Method in Python</h2>
<p>Here is an example of of a connection string you can use to connect to a database named <b>student</b>:</p>
<pre>conn = mysql.connector.connect( user='jane', password = 'my-password' , host = "192.168.5.7" , database = 'student')
</pre>
<p>There are four key arguments that a programmer needs to connect to a database:</p>
<ul>
<li><b>user</b>: The username used to connect to a database</li>
<li><b>password</b>: The users password</li>
<li><b>host</b>: IP address of the host where the database is hosted. Note that the default is <b>127.0.0.1 (localhost)</b></li>
<li><b>database</b>: Name of the database you are trying to connect to</li>
</ul>
<p>You may be wondering why there is no argument for your MySQL server’s port. In actuality, there is, and the default is <b>3306</b>. In case you set your server to use another port you can use the <b>port</b> argument.</p>
<p>The <b>connect()</b> does have more optional arguments that you can read about in the official <a href="https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html" target="_blank" rel="noopener">Connector/Python documentation</a>.</p>
<h2>How to Use MySQLConnection to Connect to a Database</h2>
<p>Here is some example code showing how to use Python and the <b>MySQLConnection</b> object to connect to a database:</p>
<pre>from mysql.connector import (connection)

conn = connection.MySQLConnection (user='jane', password = 'my-password' , host = "192.168.5.7" , database = 'student')
</pre>
<p>The rest of this database programming tutorial will use the <b>connect()</b> method.</p>
<h2>How to Execute a MySQL Query in Python</h2>
<p>In order to execute a MySQL query, you need a <b>MySQLCursor</b> object. This object interacts with a <b>MySQLConnection</b> object and the database.</p>
<p>You can create a <b>MySQLCursor</b> in Python using the following code example:</p>
<pre>cursor = cnx.cursor()
</pre>
<p>Programmers can then use the <b>execute()</b> method to process a query:</p>
<pre>my-query = “SELECT * FROM Students”
result = cursor.execute(my-query)
</pre>
<p>If you are using the <b>INSERT</b>, <b>DELETE</b>, or <b>UPDATE</b> statements, then you need to commit your connection after executing the query. You can do so with the <b>commit()</b> method, show in the following code example:</p>
<pre>conn.commit()
</pre>
<p>After you are finished interacting with the database, ensure that you close the connection and the cursor to release system resources. You can do this using the <b>close()</b> method:</p>
<pre>cursor.close()
conn.close()
</pre>
<p>Here is a fully working code example showing how to connect to a MySQL database with Python, query a table, and close the connection:</p>
<pre>import mysql.connector
from mysql.connector import Error
from mysql.connector import errorcode


try:
   connection = mysql.connector.connect(database='school', password='pass456', user='root')
   if connection.is_connected():
       dbVersion = connection.get_server_info()
       print("Succeful connection to MySQL Server version:", dbVersion)
except mysql.connector.Error as err:
   if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
       print("Please check your access credentials (username or password)")
   elif err.errno == errorcode.ER_BAD_DB_ERROR:
       print("Please check the database name")
   else:
       print(err)
connection.close()
</pre>
<p>Notice the <b>try.. except</b> clause; developers can use this catch error in their database interactions to catch any errors.</p>
<h2>Final Thoughts on Using Databases with Python</h2>
<p>In this database programming tutorial, we learned how to connect a Python application to a MySQL database. Remember, you always need to close your connection after using the database to free up system resources using the <b>close()</b> method.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/project-management-software-database/" target="_blank" rel="noopener">Project Management Software for Database Developers</a></p>
<p>The post <a href="https://www.databasejournal.com/features/python-databases/">How to Use Databases With Python</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Data Types</title>
		<link>https://www.databasejournal.com/features/sql-data-types/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Fri, 03 Feb 2023 23:04:40 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[BIGINT]]></category>
		<category><![CDATA[BINARY]]></category>
		<category><![CDATA[BLOB]]></category>
		<category><![CDATA[CHAR]]></category>
		<category><![CDATA[cheat sheet]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[CLOB]]></category>
		<category><![CDATA[CURSOR]]></category>
		<category><![CDATA[data type]]></category>
		<category><![CDATA[DATE]]></category>
		<category><![CDATA[DATETIME]]></category>
		<category><![CDATA[FLOAT]]></category>
		<category><![CDATA[INT]]></category>
		<category><![CDATA[NCHAR]]></category>
		<category><![CDATA[NTEXT]]></category>
		<category><![CDATA[NVARCHAR]]></category>
		<category><![CDATA[REAL]]></category>
		<category><![CDATA[reference sheet]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[TINYINT]]></category>
		<category><![CDATA[VarBinary]]></category>
		<category><![CDATA[VARCHAR]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16756</guid>

					<description><![CDATA[<p>In SQL, data types help to define the type of value that can be stored in a database cell, or, more specifically, in a column. There are many kinds of data types in SQL and in this database programming and administration tutorial, we will look at each one and learn their syntax, how to use [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-data-types/">SQL Data Types</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-16721" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>In SQL, <i>data types</i> help to define the type of value that can be stored in a database cell, or, more specifically, in a column. There are many kinds of data types in SQL and in this database programming and administration tutorial, we will look at each one and learn their syntax, how to use them, when to use them, their use case, and how they differ in specific relation database vendors, such as MySQL, Oracle, PostgreSQL and MS SQL Server.</p>
<p>Before we begin, if you prefer to learn in a classroom or online environment, we have a list of the <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Top Online Courses to Learn SQL</a> to help you get started.</p>
<h2>What Data Types Does SQL Have?</h2>
<p>Data types in SQL &#8211; and its offshoots &#8211; define the type, size, and range of information that can be stored in a database <i>object</i>. In SQL, objects that can have a data type include <i>columns</i>, <i>expressions</i>, <i>parameters</i>, and <i>variables</i>.</p>
<p>A <i>column</i> in a table runs up and down or vertically and consists of cells that hold data that are related to one another (hence SQL being a relational database language). A <i>variable</i> can be thought of as a box that hold data; a database programmer can look inside the box to see that data, replace it with another piece of data, or change the data &#8211; so long as it shares the same type. More on that in a moment.</p>
<p>An <i>expression</i> can be made up of one or more values, <i>operators</i>, and functions that a programmer can use to evaluate to obtain a piece of data. Think of it as a mathematic formula, though expressions do not only perform math or work on numeric values.</p>
<p><i>Parameters</i> are used to facilitate the exchange of data in what are known as <i>SQL functions</i> and <i>stored procedures</i>.</p>
<p>SQL has three main types of data types, including <i>built-in</i>, <i>user-defined alias</i>, and <i>user-defined common language runtime (CLR)</i>. These can be further broken down into categories like <i>numeric</i>, <i>string</i>, <i>date and time</i>, <i>spatial</i>, and <i>miscellaneous</i>. Within each of those categories, there are sub-categories as well, which we will discuss in-depth in the following section.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-best-practices/" target="_blank" rel="noopener">SQL Best Practices</a></p>
<h2>SQL Numeric Data Types</h2>
<p>Numeric data types in SQL represent number values as either <i>INT</i> (integer or whole numbers) or <i>FLOATS</i> (decimal point or floating-point numbers). Within these two categories, there are subtypes as well that database programmers can use to represent versions of these two numeric data types. Here is a list of all numeric data type in SQL:</p>
<ul>
<li><b>BIT:</b> Used to represent numbers of a single byte, ranging from 0 &#8211; 1</li>
<li><b>TINYINT:</b> Used to represent small integer values ranging from 0 &#8211; 255</li>
<li><b>SMALLINT:</b> Used to store integer values ranging from -32,768 &#8211; 32,767</li>
<li><b>INT:</b> Used to represent integer or whole number values ranging from -2,147,483,648 &#8211; 2,147,483,647</li>
<li><b>BIGINT:</b> Used to represent integer values ranging from -9,223,372,036,854,775,808 &#8211; 9,223,372,036,854,775,807</li>
<li><b>DECIMAL:</b> Used for decimal points numbers ranging from -10^38 + 1 &#8211; 10^38 -1</li>
<li><b>NUMERIC:</b> Used for numbers ranging from -10^38 + 1 &#8211; 10^38 -1</li>
<li><b>FLOAT:</b> Used for decimal numbers ranging from -1.79E+308 &#8211; 1.79E+308</li>
<li><b>REAL:</b> Used for <i>approximate</i> floating-point numbers ranging from -3.40E + 38 &#8211; 3.40E + 38</li>
<li><b>SMALLMONEY:</b> Used for monetary values ranging from -214,748.3648 &#8211; 214,748.3647. <i>Specific to MS SQL Server</i></li>
<li><b>MONEY:</b> Used for monetary values ranging from -922,337,203,685,477.5808 &#8211; 922,337,203,685,477.5807. <i>Specific to MS SQL Server</i></li>
</ul>
<h2>SQL String and Character Data Types</h2>
<p>Character and text data types in SQL consists of text-based values, which can include the upper and lowercase version of any letter ranging from <b>a-z</b>, <b>A-Z</b>, and special characters like <b>!@#$%^&amp;*()</b>. SQL has two types of character and string data types: <i>character and strings</i> and <i>Unicode characters and strings</i>.</p>
<p>Without getting too deep into the subject (it is beyond the scope of this tutorial), Unicode is an encoding standard used to assign a unique numeric value to a letter, digit, or symbol, to ensure it works regardless of language or script being used. For instance, the Unicode for an uppercase letter <b>A</b> is <b>U+0041</b>, while the Unicode for a lowercase letter <b>a</b> is <b>U+0061</b>.</p>
<p>Below is a list of the Character and String data types in SQL:</p>
<ul>
<li><b>CHAR:</b> Used for fixed length text with a maximum length of 8,000 characters</li>
<li><b>VARCHAR:</b> Used for variable-length text with a maximum length of 8,000 characters</li>
<li><b>VARCHAR(max):</b> Used for variable-length text with provided max characters. Note that this is not supported in MySQL flavor of SQL</li>
<li><b>TEXT:</b> Variable-length text values with a maximum size of 2GB worth of data</li>
</ul>
<p>Here is a list of the different Unicode Character and String data types allowed in SQL. It should be noted that these data types are not supported in MySQL:</p>
<ul>
<li><b>NCHAR:</b> Used for fixed length text with a maximum length of 4,000 characters</li>
<li><b>NVARCHAR:</b> Used for variable-length text with a maximum length of 4,000 characters</li>
<li><b>NVARCHAR(max):</b> Used for variable-length storage with max characters provided</li>
<li><b>NTEXT:</b> Used for variable-length text with a maximum storage capacity of 1GB</li>
</ul>
<p>Learn more abut different flavors of SQL in our tutorials: <a href="https://www.databasejournal.com/mysql/what-is-mysql/" target="_blank" rel="noopener">What is MySQL</a> and <a href="https://www.databasejournal.com/features/what-is-postgresql/" target="_blank" rel="noopener">What is PostgreSQL</a>.</p>
<h2>Date and Time Data Types in SQL</h2>
<p>As you might have guessed, date and time data types are used for date and time values. Here is a list of the supported date and time data types supported in SQL:</p>
<ul>
<li><b>DATE:</b> Stores date values in the <b>YYYY-MM-DD</b> format</li>
<li><b>TIME</b> Stores time values in the <b>HH:MI:SS</b> format</li>
<li><b>DATETIME:</b> Stores both date <i>and</i> time values in the <b>YYYY-MM-DD HH:MI:SS</b> format</li>
<li><b>TIMESTAMP:</b> Used to store the number of seconds that have passed since the Unix epoch, or <b>1970-01-01 00:00:00 UTC</b></li>
<li><b>YEAR:</b> Used to store a year value in either a 2-digit or 4-digit format, ranging from <b>1901 &#8211; 2155</b> in 4-digit format, or <b>70 &#8211; 69</b> in a 2-digit format, which represents the time frame of <b>1970 &#8211; 2069</b></li>
</ul>
<h2>Binary Data Types in SQL</h2>
<p><i>Binary data</i> is data that is represented by <b>1s</b> and <b>0s</b>; in SQL, binary data types are usually used for binary data such as images or text files. SQL supports the following types of binary data types:</p>
<ul>
<li><b>BINARY:</b> Used when the size of the data is consistent; used for fixed-length binary data with a maximum length of 8,000 bytes</li>
<li><b>VARBINARY:</b> Used for variable-length binary data up to 8,000 bytes</li>
<li><b>VARBINARY(max):</b> Used for variable-length binary data with a provided maximum byte size</li>
<li><b>IMAGE:</b> Used for variable-length binary data with 2GB maximum size</li>
</ul>
<h2>Other Data Types in SQL</h2>
<p>SQL supports other data types not listed in this tutorial (at the time of this writing) &#8211; the data types contained herein are the most commonly used. In addition, it should be noted that vendor-specific relational databases &#8211; or other flavor of SQL &#8211; like MySQL, T-SQL, Oracle, and MS SQL Server have their own variations and syntax for the data types in this database programming tutorial. We will cover those in a future tutorial, which will be linked here, so be sure to check back often.</p>
<p>Before we wrap up this tutorial, however, let’s discuss four more commonly used SQL data types:</p>
<ul>
<li><b>BLOB:</b> Used for storing large binary objects</li>
<li><b>CLOB:</b> Used for storing large character objects up to 2GB in size</li>
<li><b>JSON:</b> Used to store JSON data and JSON documents</li>
<li><b>XML:</b> Used to store XML schema data</li>
</ul>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-comments/" target="_blank" rel="noopener">How to Comment in SQL</a></p>
<p>The post <a href="https://www.databasejournal.com/features/sql-data-types/">SQL Data Types</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Use SQL WHERE Clause</title>
		<link>https://www.databasejournal.com/features/sql-where-clause/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 08:04:47 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[cheat sheet]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reference sheet]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL syntax]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[WHERE]]></category>
		<category><![CDATA[WHERE clause]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16753</guid>

					<description><![CDATA[<p>When querying a relational database, database programmers and administrators will often need to filter the records returned or extract specific records that meet a given criteria. In this database programming tutorial, we will look at the SQL WHERE clause, learn its syntax, and preview several code examples showing its use. Read: How to Use the [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-where-clause/">How to Use SQL WHERE Clause</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-16721" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="auto, (max-width: 300px) 100vw, 300px" /><br />
When querying a relational database, database programmers and administrators will often need to filter the records returned or extract specific records that meet a given criteria. In this database programming tutorial, we will look at the SQL <b>WHERE</b> clause, learn its syntax, and preview several code examples showing its use.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-select/" target="_blank" rel="noopener">How to Use the SQL SELECT Statement</a></p>
<h2>SQL WHERE Clause</h2>
<p>As stated in the intro, the SQL <b>WHERE</b> clause is used when we need to filter the records returned from a table to show a result based on a given condition or set of criteria. The syntax for the <b>WHERE</b> clause is:</p>
<pre>SELECT column1, column2, column3
FROM name-of-table
WHERE condition
</pre>
<p>In addition to being used alongside the <b>SELECT</b> statement, the SQL <b>WHERE</b> clause can be used with <b>UPDATE</b> and <b>DELETE</b> statements as well.</p>
<h2>SQL WHERE Clause Code Example</h2>
<p>For our first code example, let&#8217;s assume that we have a database with a table named <b>Superheroes</b> that contains the <b>HeroNames</b>, <b>HeroID</b>, and <b>SuperPowers</b> of known super heroes. As a sample dataset, let&#8217;s say the following entries exist in our <b>Superheroes</b> table:</p>
<pre>HeroNames SuperPowers HeroID
AwesomePossum Play dead 110
Whatawoman Jump rope of doom 120
TheSpoiler Ruins movie endings in a single bound 130
</pre>
<p>If we want to only pull up the record for super heroes whose name is <b>AwesomePossum</b>, we would write the follow SQL query, which shows how to use the <b>WHERE</b> clause:</p>
<pre>SELECT * FROM Superheroes
WHERE HeroNames'AwesomePossum;'
</pre>
<p>Running this query would result in the following output:</p>
<pre>AwesomePossum Play dead 110
</pre>
<p>The above SQL example showed us how to use the <b>WHERE</b> clause to query a condition based on a text value &#8211; hence the inclusion of single quotation marks in our query (do not use double quotations!). If we want to query a numeric value using the <b>WHERE</b> clause, we would omit the single quotation marks, as shown in the following SQL example:</p>
<pre>SELECT * FROM Superheroes
WHERE HeroID=110;
</pre>
<p>Running this query will give us the result:</p>
<pre>AwesomePossum Play dead 110
</pre>
<p><strong>Read: </strong><a href="https://www.databasejournal.com/features/sql-select-distinct/" target="_blank" rel="noopener">How to Use SQL SELECT DISTINCT Statement</a></p>
<h2>SQL WHERE Clause Operators</h2>
<p>Of course, using only the <b>equals</b> or <b>=</b> operator to determine criteria in an SQL <b>WHERE</b> clause is very limiting. Fortunately, there are a number of other operators you can use in conjunction with the <b>WHERE</b> clause to set query criteria. SQL <b>WHERE</b> clause operators include:</p>
<ul>
<li><b>=</b> Signifies values must equal <i>x</i></li>
<li><b>&gt;</b> Signifies values must be greater than <i>x</i></li>
<li><b>&lt;</b> Signifies values must be less than <i>x</i></li>
<li><b>&gt;=</b> Signifies values must be greater than or equal to <i>x</i></li>
<li><b>&lt;=</b> Signifies values must be less than or equal to <i>x</i></li>
<li><b>&lt;&gt;</b> Signifies values must not be equal to <i>x</i></li>
<li><b>BETWEEN</b> Signifies values must be within a range</li>
<li><b>IN</b> Used to specifiy more than one possible value in a column</li>
<li><b>LIKE</b> Used for searching a given pattern</li>
</ul>
<h3>SQL BETWEEN Operator Example</h3>
<p>To use the <b>BETWEEN</b> operator with a <b>WHERE</b> clause on our example table, we would write the following SQL statement:</p>
<pre>SELECT * FROM Superheroes
WHERE HeroID BETWEEN 110 and 115;
</pre>
<p>Executing this SQL query would result in the output:</p>
<pre>AwesomePossum Play dead 110
</pre>
<h3>SQL IN Operator Example</h3>
<p>Here is an example of how to use the <b>IN</b> operator with a <b>WHERE</b> clause in SQL:</p>
<pre>SELECT * FROM Superheroes
WHERE HeroNames ('AwesomePossum', 'Whatawoman');
</pre>
<p>Running the above query on our sample dataset would return the data for the <b>AwesomePossum</b> and <b>Whatawoman</b> records.</p>
<h3>SQL LIKE Operator Example</h3>
<p>Here is an example showing how to use the <b>LIKE</b> operator with a <b>WHERE</b> clause in SQL:</p>
<pre>SELECT * FROM Superheroes
WHERE HeroNames LIKE 'A%';
</pre>
<p>In this example SQL query, we are searching the <b>Superheroes</b> table for any records where <b>HeroNames</b> start with <b>A</b>. The <b>%</b> symbol is used to say that any value <i>after</i> <b>A</b> is okay. Using our dataset sample, the result of running this query would be:</p>
<pre>AwesomePossum Play dead 110
</pre>
<p>Had their been another hero with a name that began with <b>A</b>, it, too, would have been returned.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn SQL</a></p>
<p>The post <a href="https://www.databasejournal.com/features/sql-where-clause/">How to Use SQL WHERE Clause</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>What is PostgreSQL?</title>
		<link>https://www.databasejournal.com/features/what-is-postgresql/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 06:31:47 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[relational database]]></category>
		<category><![CDATA[Relational Database Management System]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16751</guid>

					<description><![CDATA[<p>PostgreSQL is one of the world&#8217;s most widely used database systems in the world, offering support for not only structured query language (SQL), but JSON as well, making it a great choice for database-driven enterprise applications. In this database programming and database administration tutorial, we discuss what PostgreSQL is, its relation to SQL, and the [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/what-is-postgresql/">What is PostgreSQL?</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-16752" src="https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-291x300.png" alt="PostgreSQL" width="291" height="300" srcset="https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-291x300.png 291w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-993x1024.png 993w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-768x792.png 768w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-1489x1536.png 1489w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-696x718.png 696w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-1068x1101.png 1068w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-1920x1980.png 1920w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials-407x420.png 407w, https://assets.databasejournal.com/uploads/2023/01/postgresql-tutorials.png 1985w" sizes="auto, (max-width: 291px) 100vw, 291px" /></p>
<p>PostgreSQL is one of the world&#8217;s most widely used database systems in the world, offering support for not only structured query language (SQL), but JSON as well, making it a great choice for database-driven enterprise applications. In this database programming and database administration tutorial, we discuss what PostgreSQL is, its relation to SQL, and the benefits of working with the hybrid database system.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/mysql/what-is-mysql/" target="_blank" rel="noopener">What is MySQL?</a></p>
<h2>Overview of PostgreSQL</h2>
<p>PostgreSQL, like other offshoots of SQL database systems, is often viewed as a database programming language. However, this is a misnomer, as PostgreSQL is actually an open source relational database system. What is unique about PostgreSQL is that it supports not only structured query language (SQL) querying (like other relational database management systems), but JSON as well, which is used for non-relational database queries.</p>
<p>The phrase <i>relational</i> in the realm of databases refers to the way in which data is structured in a database. Using structures known as <i>tables</i>, which are comprised of rows (horizontal) and columns (vertical) that intersect to create a <i>cell</i> that stores a singular data point, relational databases store data in such a way that information has relationships with other pieces of data.</p>
<p>For instance, you may have a table with columns named <b>FirstName</b>, <b>LastName</b>, and <b>Social</b>. These columns, which run vertically or up and down, hold that representative of the column headers. Database administrators can infer that column <b>FirstName</b> will hold &#8220;first names&#8221;.</p>
<p>The same logic follows for <b>LastName</b> (for &#8220;last names&#8221;) and <b>Social</b> (presumably for social security numbers). Meanwhile, the rows running horizontally will hold those data points. The first row, for instance, might contain these three data points:</p>
<pre>FirstName  LastName  Social
Ronnie     Payne     111-11-1111
</pre>
<p>Because we are using a relational database, the data points <b>Ronnie</b>, <b>Payne</b>, and <b>111-11-1111</b> are all related. If we queried the database to find all records associated with <b>Social</b> whose value is <b>111-11-1111</b>, then the values <b>Ronnie</b> and <b>Payne</b> would be returned as well, but no other records, <i>unless</i> they also contained the <b>Social</b> value of <b>111-11-1111</b>.</p>
<p>That is a loose example of how relational databases work.</p>
<p>One last point about relational databases. You may also here a relational database referred to as a <i>relational database management system (RDBMS); </i>the two, however, are not the same thing. A relational database is simply a type of database, while an RDBMS is an entire database system, including database management tools.</p>
<p>To learn more, check out our tutorial: <a href="https://www.databasejournal.com/features/relational-database-management-system/" target="_blank" rel="noopener">What is a Relational Database Management System?</a></p>
<h2>What are the Benefits of PostgreSQL</h2>
<p>PostgreSQL first hit the scene back in 1986 at the University of Berkeley in California. Originally called &#8220;POSTGRES&#8221; after the original &#8220;Ingres&#8221; database. The intention of its developers was to create a database that supported multiple data types, which it currently does.</p>
<p>With over two decades of support and development, PostgreSQL has a number of benefits for both database developers and database administrators, which we will highlight below.</p>
<h3>Language Support</h3>
<p>PostgreSQL supports many programming languages, including, of course, SQL. Other languages supported by the relational database include:</p>
<ul>
<li>Java</li>
<li>JavaScript</li>
<li>Perl</li>
<li>Python</li>
<li>R</li>
<li>Shell</li>
<li>Tcl</li>
<li>Lua</li>
<li>Go and Golang</li>
<li>C#</li>
<li>C and C++</li>
<li>Ruby</li>
</ul>
<h3>Support for Data Types</h3>
<p>As stated, PostgreSQL was created with the thought of having the primary feature of supporting many data types. To that end, PostgreSQL supports the following data types:</p>
<ul>
<li>Primitives (integers, strings, Booleans, datetimes)</li>
<li>Geometric types</li>
<li>hstore type</li>
<li>Ranges</li>
<li>Monetary types for currency types</li>
<li>Multidimensional arrays</li>
<li>Network addresses</li>
<li>JSON objects</li>
</ul>
<h3>Open Source</h3>
<p>PostgreSQL is an open source relational database, meaning its source code is available for download. With this codebase in hand, developers can tailor the database to their organizations needs. This also means that the codebase is available to the general public, who help contribute to the reliability, functionality, and security of the database.</p>
<p>Further, since PostgreSQL is open source, it is free, making it an ideal choice for budget conscience software development teams looking for license free database options.</p>
<h3>Hybrid Database</h3>
<p>PostgreSQL offers support for both relational <i>and</i> non-relational queries. This means that database developers and database administrators can perform SQL queries on rows containing transaction or statistics data (where the data is related) while also using NoSQL to store and process JSON documents.</p>
<p>This hybrid functionality is great for flexible development shops that require multiple types of database systems.</p>
<h3>Data Compliance</h3>
<p>Another benefit of PostgreSQL has to do with data compliancy. PostgreSQL supports ACID semantics, which are used for transactions. In addition PostgreSQL allows for <b>foreign keys</b>, <b>joins</b>, <b>views</b>, <b>triggers</b>, and stored procedures.</p>
<p>Binary large objects, like images, videos, and sound can also be stored in PostgreSQL databases, making it an excellent choice for media heavy, database-driven applications.</p>
<h3>PostgreSQL is Object Oriented</h3>
<p>PostgreSQL is also an <i>object-relational database</i>, meaning it supports object oriented programming (OOP) concepts such as classes, objects, function overloading, and custom data type creation. This includes support for inheritance as well, as a child table can inherit columns from parent tables, making PostgreSQL a truly powerful database option.</p>
<h3>PostgreSQL is Extensible</h3>
<p>In computer programming, the phrase <i>extensible</i> means that you can add to the functionality of a given technology &#8211; usually the language or database itself. PostgreSQL is an extensible database, meaning database programmers and database administrators can extend the functionality of PostgreSQL by adding new data types, index methods, aggregate functions, functions, and operators.</p>
<h3>Spatial Data</h3>
<p>PostgreSQL is well-known for its support of spatial data, such as having a specific data type for handling geometrical objects and geographic objects. Using the PostGIS extension, PostgreSQL can be used as a geospatial data store, making it popular among government agencies, geographic information systems (GIS), and location-based service providers.</p>
<h2>PostgreSQL Features</h2>
<p>PostgreSQL supports the following database features:</p>
<ul>
<li>Foreign keys</li>
<li>Table inheritance</li>
<li>Object orientation via classes and objects</li>
<li>User-defined types</li>
<li>Multiple data types</li>
<li>Async replication</li>
<li>Multi-version concurrency control (MVCC) architecture</li>
<li>Nested transactions</li>
<li>Tablespaces</li>
<li>Point-in-time recovery</li>
</ul>
<h2>Final Thoughts on PostgreSQL</h2>
<p>Is PostgreSQL the right solution for your software development team? That will depend largely on your organizations needs. If your team wants a flexible database that can handle both SQL and NoSQL queries, then you should strongly consider working with PostgreSQL. Likewise, if your company relies works with geospatial or location-based datasets, you can not go wrong choose PostgreSQL as your database.</p>
<p>On the other hand, if you develop web applications that are database-driven, you might want to choose a PostgreSQL alternative such as MySQL. If your development team technology stack is heavily dependent on Microsoft-related technologies and languages like C# and ASP.NET, MSSQL Server is probably a better option.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn SQL</a></p>
<p>The post <a href="https://www.databasejournal.com/features/what-is-postgresql/">What is PostgreSQL?</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Prevent SQL Injections</title>
		<link>https://www.databasejournal.com/features/prevent-sql-injections/</link>
		
		<dc:creator><![CDATA[technologyadv]]></dc:creator>
		<pubDate>Thu, 12 Jan 2023 23:23:37 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[database development]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[database security]]></category>
		<category><![CDATA[injection attack]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16749</guid>

					<description><![CDATA[<p>An SQL injection is an attack on a database server where a malicious actor enters &#8211; or injects &#8211; some nefarious input in a form, other than the expected input. The attack can be used to gain access to restricted data, wipe out databases, and examine the server info, among other things. In this database [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/prevent-sql-injections/">How to Prevent SQL Injections</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-16721" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>An <i>SQL injection</i> is an attack on a database server where a malicious actor enters &#8211; or injects &#8211; some nefarious input in a form, other than the expected input. The attack can be used to gain access to restricted data, wipe out databases, and examine the server info, among other things.</p>
<p>In this database programming tutorial, database developers and database administrators will learn a number of ways that a hacker can exploit your database. This database tutorial will also show you how you can protect your application from these vulnerabilities.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-best-practices/" target="_blank" rel="noopener">SQL Best Practices</a></p>
<h2>What are the Types of SQL Injections?</h2>
<p>As mentioned earlier, SQL injection attacks depend on some input other than the expected input into a form. Simply put, the attacker defines the goal of the exploit, then passes an SQL statement in a form field, instead of the expected input, such as a name or number.</p>
<p>In the following section we will answer the question: What are the different types of SQL injection attacks?</p>
<h3>SQL Injection Due to 1=1</h3>
<p>This is an attack based on the fact that the condition <b>1=1</b> is always <b>TRUE</b>. This means that whenever a query runs, a <i>true</i> result is always returned, regardless of the condition (a <b>WHERE</b> clause).</p>
<p>This kind of exploit enables a hacker to gain unauthorized access to data. Here is an example of a normal SQL query:</p>
<pre>SELECT *  from Student WHERE age=27;
</pre>
<p>Here is an example of a malicious SQL query demonstrating a <b>1=1</b> attack:</p>
<pre>SELECT *  from Student WHERE age=27 OR 9=9;
</pre>
<p>As you can see from the above code example, if a malicious user enters <b>27 OR 9=9</b> in the form field, instead of just <b>27</b>, then they will be able query the database for all student records regardless of the query condition.</p>
<p>Notice that the given example uses <b>9=9</b> instead of <b>1=1</b>. This was intentionally chosen to show you that you do not have to only use <b>1=1</b> to make the exploit in the section.</p>
<p>You can use any <b>number=number</b> or character value on both sides of the equal sign ( e.g <b>&#8216;g&#8217;=&#8217;g&#8217;</b> ).</p>
<h3>SQL Injection Due to &#8211; &#8211;</h3>
<p>The double-dash (<b>&#8212;</b>) character sequence is used to write comments in your SQL query. However, a hacker can take advantage of this property to remove/void certain segments of your SQL query. For example, to bypass password checks and query conditions.</p>
<p>Here is an example of how to perform an SQL <b>&#8212;</b> attack:</p>
<pre>SELECT * FROM Users WHERE username = 'userX'--' AND password = '' 
</pre>
<p>The above database query will allow <b>userX</b> to access the <b>Users</b> table, without making a password check.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/mysql/database-administrator-certifications/" target="_blank" rel="noopener">Best Certifications for Database Administrators</a></p>
<h3>SQL Injection Due to Batched SQL Statements</h3>
<p>Depending on the database server you are using, you may be able to query multiple (batched) statements at once.</p>
<p>A malicious actor can exploit this to add their own SQL statement. Take an example of a user who wants to access all student records. If this user is malicious, they could also add a query to <b>DROP</b> the <b>Teacher</b> table:</p>
<pre>SELECT *  from Student WHERE subject="Japanese"; DROP TABLE Teacher;
</pre>
<h3>SQL Injection Due to UNION</h3>
<p>The <b>UNION</b> command is used to query results from two tables. Note that the columns selected for each table used must have the same data type. A hacker can take advantage of this in the following manner:</p>
<pre>SELECT fname, age FROM Student UNION SELECT fname, age FROM Teacher;
</pre>
<h3>SQL Injection Based on &#8220;&#8221;=&#8221;&#8221;</h3>
<p>The <b>&#8220;&#8221;=&#8221;&#8221;</b> SQL injection attack is similar to the <b>1=1</b> injection. A hacker simply makes the <b>&#8220;&#8221; OR &#8220;&#8221;=&#8221;&#8221;</b> entry instead of an expected value to meet the query condition. Hence, the condition will always be <b>true</b> regardless of the <b>WHERE</b> clause:</p>
<pre>SELECT * FROM Student WHERE fname= "" OR ""="";
</pre>
<h3>SQL Injection to Examine Database</h3>
<p>There are typically three steps involved in database vulnerability testing or hacking: (1) reconnaissance, (2) planning, and (3) attack. It is interesting to note that the military also uses a similar framework before making an attack.</p>
<p>Reconnaissance (or simply recon) refers to gathering info about your intended target. This is very important to help you in the next step in your hacking process &#8211; planning.</p>
<p>A database hacker is able to gather invaluable information about your database, such as the version, name, and distributor using either of the following SQL statements:</p>
<pre>SELECT version();
STATUS;
</pre>
<h2>How to Prevent SQL Injections</h2>
<p>The database exploits in the above section shows you that it is important to protect your database against such known vulnerabilities. Take note that the responsibility is upon you, the application developer or database administrator, to provide protections for your database (and not the database vendor).</p>
<p>One way of protecting your database is using <i>prepared statements</i>. These are statements that do not directly insert the values they obtain from the user. In a prepared statement, the SQL server binds the values at execution time.</p>
<p>Here is a code example of how you can use prepared statements in PHP:</p>
<pre> 
$stmt = $db-&gt;prepare("INSERT INTO Student(fname, lname, age) VALUES (?, ?, ?)");
</pre>
<p>In this code, the <b>?</b> is used to replace the parameters. The <b>bind_param()</b> method is then used to bind the respective values to the given parameters.</p>
<pre>$stmt-&gt;bind_param("ssi", $fname, $lname, $age);
</pre>
<p>After, you can now execute the statement:</p>
<pre>$stmt-&gt;execute();
</pre>
<p>When binding the values, notice the string &#8220;<b>ssi</b>&#8221; arguments. This string specifies the data type of each input value. There are four possible letter use can use to represent the respective types:</p>
<ul>
<li><b>d:</b> double</li>
<li><b>i:</b> integer</li>
<li><b>s:</b> string</li>
<li><b>b:</b> BLOB</li>
</ul>
<h2>Final Thoughts on How to Prevent SQL Injections</h2>
<p>It is important for database programmers and database administrators to protect your database from SQL Injections. Remember, databases do not usually ship with this protection, so it is upon you, the developer or admin, to implement it.</p>
<p><strong>Read:</strong> <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn SQL</a></p>
<p>The post <a href="https://www.databasejournal.com/features/prevent-sql-injections/">How to Prevent SQL Injections</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>What is a Relational Database Management System</title>
		<link>https://www.databasejournal.com/features/relational-database-management-system/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Tue, 20 Dec 2022 03:59:52 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[Relational Database Management System]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16741</guid>

					<description><![CDATA[<p>If you are new to database administration or database development, you have no doubt heard the phrase “relational database management system” being tossed around. As database programmers or those that work with databases, we tend to think of database systems in terms of languages or platforms, like SQL, MySQL, or T-SQL. In today’s database programming [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/relational-database-management-system/">What is a Relational Database Management System</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone wp-image-16721 size-medium" src="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg" alt="SQL Tutorials" width="300" height="200" srcset="https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-300x200.jpeg 300w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1024x683.jpeg 1024w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-768x512.jpeg 768w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1536x1024.jpeg 1536w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-2048x1365.jpeg 2048w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-696x464.jpeg 696w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1068x712.jpeg 1068w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-1920x1280.jpeg 1920w, https://assets.databasejournal.com/uploads/2022/09/SQL-tutorials-tips-630x420.jpeg 630w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>If you are new to database administration or database development, you have no doubt heard the phrase “relational database management system” being tossed around. As database programmers or those that work with databases, we tend to think of database systems in terms of languages or platforms, like SQL, MySQL, or T-SQL. In today’s database programming tutorial, we are going to discuss RDBMS systems and answer the question: “What is a Relational Database Management System” and provide some tips for working with one.</p>
<p><b>Read:</b> <a href="https://www.databasejournal.com/features/mysql-courses-online/" target="_blank" rel="noopener">Top Online Courses for Learning MySQL</a></p>
<h2>What is a Database?</h2>
<p>While this tutorial deals specifically with relational databases, we should briefly discuss what database software, in general, is. To that end, a <i>database</i> is a system or program where data is stored. More than that, databases tend to store information or data in a way that is organized, easily accessible, and able to be manipulated. Manipulation of data or datasets, in this sense refers to being able to add, edit, delete, append, or <i>query</i> (we’ll cover this more later) information.</p>
<h2>What is a Relational Database?</h2>
<p>A <i>relational database</i> is a type of database that uses structures known as <i>tables</i> to store data for later use. We call it “relational” because of the method that data is stored &#8211; that is, in relation to other data. For instance, a table within a database may contain <i>first names</i>, <i>last names</i>, and <i>social security numbers</i>. Suppose we have the following information in a table:</p>
<pre>Ronnie Payne 555-55-5555
Seth Rollins 666-66-6666
Clark Griswold 777-77-777
</pre>
<p>In the above example, the name <b>Ronnie, last name <b>Payne</b>, and social security <b>555-55-5555</b> all belong to one <i>record</i> or group of information. If I want to be able to find out <b>Ronnie’s</b> social security number, then those two pieces of data must be connected &#8211; or <i>related</i> &#8211; for me to retrieve the information. Otherwise, all you have is a database full of random information that means nothing on its own.</b></p>
<p>To better understand this thought, we have to look at how tables are made, which we discuss in the next section.</p>
<h3>What are Tables?</h3>
<p>Tables in a database are used for storing information in an organized &#8211; and related &#8211; manner. You can think of a table as a grid, such as you might see in Microsoft Excel or other spreadsheet software. Tables are made up of <i>columns</i>, which run up and down or vertically, and <i>rows</i>, which run side to side or horizontally. Where columns and rows intersect is known as a <i>cell</i>, or, in database terminology, a <i>record</i>. Consider the following image:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-16742" src="https://assets.databasejournal.com/uploads/2022/12/sql-what-is-rdbms.png" alt="What is an RDBMS?" width="321" height="112" srcset="https://assets.databasejournal.com/uploads/2022/12/sql-what-is-rdbms.png 321w, https://assets.databasejournal.com/uploads/2022/12/sql-what-is-rdbms-300x105.png 300w" sizes="auto, (max-width: 321px) 100vw, 321px" /></p>
<p>In the above image, the word <b>First Name</b> acts as the header for our first column, letting the database administrator or programmer know what the rest of the data in that column represents. For instance, the <b>First Name</b> column holds values <b>Ronnie</b>, <b>Seth</b>, and <b>Clark</b>. Likewise, the second column, <b>Last Name</b> holds the values <b>Payne</b>, <b>Rollins</b>, and <b>Griswold</b>.</p>
<p>Row one, in this instance, would contain the following information:</p>
<pre>Ronnie Payne 555-55-5555
</pre>
<p>Row two contains:</p>
<pre>Seth Rollins 666-66-6666
</pre>
<p>And so on.</p>
<p>Further, each column will contain a <i>data type</i>: text-based values are known as <b>string data types</b>, while numeric values are known as <b><b>integers</b></b> for whole numbers and <b><i>floats</i></b>for decimal-point numbers.</p>
<h2>What is a Relational Database Management System</h2>
<p>Thus far, we have discussed databases as a whole, and relational databases; in this section, we will discuss relational database management systems &#8211; also known as RDBMS &#8211; and what they are used for.</p>
<p>A relational database management system (RDBMS) is software that lets database administrators and database programmers work with, view, manipulate, create, update, edit, delete, or query information stored in a relational database. This data manipulation occurs through a language known as <i>Structured Query Language or <b>SQL</b> &#8211; pronounced “S-Q-L”.</i></p>
<p>You can learn more about SQL in our tutorial: <a href="https://www.databasejournal.com/features/what-is-sql/" target="_blank" rel="noopener">What is SQL?</a></p>
<h2>Types of Relational Database Management Systems</h2>
<p>Just as there are different types of database systems, so, too, are there different types of RDBMS. Some of the most popular relational database management systems include:</p>
<ul>
<li>MySQL</li>
<li>PostgreSQL</li>
<li>Oracle DB</li>
<li>SQL Server</li>
<li>SQLite</li>
</ul>
<p>We discuss each of this in more depth in our upcoming tutorial: What Are the Different Types of RDBMS?</p>
<p>The post <a href="https://www.databasejournal.com/features/relational-database-management-system/">What is a Relational Database Management System</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Best Practices</title>
		<link>https://www.databasejournal.com/features/sql-best-practices/</link>
		
		<dc:creator><![CDATA[Ronnie Payne]]></dc:creator>
		<pubDate>Tue, 20 Dec 2022 03:47:59 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[database development]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[relational database]]></category>
		<category><![CDATA[Relational Database Management System]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[structured query language]]></category>
		<guid isPermaLink="false">https://www.databasejournal.com/?p=16740</guid>

					<description><![CDATA[<p>Structured Query Language (SQL) is a simple, yet powerful database programming and administration language used to manipulate data stored in a relational database or relational database management system (RDBMS). It is easy to learn compared to a lot of traditional programming languages. While that is great for both new database developers and veterans alike, it [&#8230;]</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-best-practices/">SQL Best Practices</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Structured Query Language (SQL) is a simple, yet powerful database programming and administration language used to manipulate data stored in a relational database or relational database management system (RDBMS). It is easy to learn compared to a lot of traditional programming languages. While that is great for both new database developers and veterans alike, it can lead to issues; since learning the database language is so simple, programmers can often overlook best practices and just dive right in.</p>
<p>To avoid this issue, this database programming tutorial will cover the best practices for writing SQL code and querying relational databases.</p>
<p>Looking to learn SQL or database development in an online course? We have a list of the <a href="https://www.databasejournal.com/features/sql-courses-online/" target="_blank" rel="noopener">Best Online Courses to Learn SQL</a> to help get you started.</p>
<h2>Best Practices for Structure Query Language</h2>
<p>Below is a list of best practices for database programmers and database administrators to follow when querying relational databases with SQL.</p>
<h3>SQL Keywords Should Use Uppercase</h3>
<p>Perhaps one of the most basic best practices for SQL is to always ensure that you are using uppercase letters for your SQL keywords. This can be a bone of contention among db admins, as different flavors of SQL will have different casing for code; in general, however, the core SQL keyword commands should always use uppercase, such as:</p>
<pre>SELECT FirstName, LastName FROM Customers;
</pre>
<p>or</p>
<pre>SELECT * from Customers;
</pre>
<p>versus writing it:</p>
<pre>--THIS IS WRONG
select FirstName, LastName from Customers;
</pre>
<p>While some debate the matter, using uppercase for SQL functions is also a best practice &#8211; if nothing else, for consistency.</p>
<h3>Comment Your SQL Code</h3>
<p>One of the most important best practices in any programming language is to always add comments to your code. This is true of your SQL statements as well. Commenting is a way to leave notes to yourself &#8211; or other developers &#8211; explaining what a particular line or block of code was meant for.</p>
<p>You should only comment your SQL code when a statement is not self-explanatory or its intent is not readily apparent. Adding comments to code whose purpose is obvious is redundant and can lead tl clutter in your codebase &#8211; something you want to avoid. Try to create a good balance and <i>only</i> comment when it makes sense to do so.</p>
<p>Here is an example of how to comment in SQL:</p>
<pre>-- This is a comment
SELECT * FROM Customers;
</pre>
<p>Single-line &#8211; or inline &#8211; comments in SQL begin with two <b>&#8212;</b> symbols. When the SQL interpreter sees the <b>&#8212;</b> symbols, it ignores the remaining code on that line.</p>
<p>You can also leave more than one line of comments. There are two ways to achieve this in SQL. The first involves simply leaving multiple single-line comments, as show in this code example:</p>
<pre>--This is a comment
--This is also a comment
SELECT * FROM Customers;
</pre>
<p>Another way to leave more than one comment is to use <i>multi-line commenting</i>. In multi-line comments, you start the comment by using the opening <b>/*</b> symbol. You then right your comments and close the multi-line comment using the closing <b>*/</b> symbol. Here is an example of how to write multi-line comments in SQL:</p>
<pre>/*This is the start of a multi-line comment
This is a continuation of our multi-line comment
SQL does not read this line or any other line
Until we close the comment.
*/
SELECT * FROM Customers;
</pre>
<h3>The SELECT Asterisk Problem</h3>
<p>In our SQL examples above, you may have noticed that we use the <b>SELECT *</b> statement. If you are unfamiliar, <b>SELECT</b> lets you choose data from a given table. If we add the <i>wildcard</i> asterisk character (<b>*</b>), then all of the information in a table will be chosen or processed. This becomes a problem in Big Data scenarios or where large amounts of data exist in a table. Instead of selecting every column in a table, instead, choose only the columns you <i>need</i> to query. For instance, if you only need the <b>First Name</b> from our <b>Customers</b> table example, you would use:</p>
<pre>SELECT FirstName FROM Customers;
</pre>
<p>That isn&#8217;t to say you <i>shouldn&#8217;t</i> ever use <b>SELECT *</b> &#8211; just make sure you only use it in scenarios where you actually need all of the data in a table.</p>
<h3>Format Queries</h3>
<p>Another SQL best practice is to format the text in yoru queries. This means that yuo want to place each clause on its own line. This makes your code easier to read and less prone to mistakes. For example, instead of writing:</p>
<pre>SELECT FirstName, LastName, FROM Customers WHERE FirstName = 'Ronnie';
</pre>
<p>You would want to format the query this:</p>
<pre>SELECT
	FirstName,
	LastName
FROM
	Customers
WHERE
	FirstName = 'Ronnie';
</pre>
<p>This makes understanding the SQL easier and finding errors much simpler.</p>
<h2>Final Thoughts on SQL Best Practices</h2>
<p>There are many best practices for writing clean, efficient, and maintainable SQL statements; this database programming tutorial only scratches the surface. We will update this listing from time to time, so be certain to check back often to learn more tips for writing quality SQL.</p>
<p>The post <a href="https://www.databasejournal.com/features/sql-best-practices/">SQL Best Practices</a> appeared first on <a href="https://www.databasejournal.com">Database Journal</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
