<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hannahthesailor</title>
    <description>The latest articles on DEV Community by hannahthesailor (@hannahthesailor).</description>
    <link>https://dev.to/hannahthesailor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1272840%2F1002e888-f25e-4c02-9286-5e431715ac1a.png</url>
      <title>DEV Community: hannahthesailor</title>
      <link>https://dev.to/hannahthesailor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hannahthesailor"/>
    <language>en</language>
    <item>
      <title>Constraints and Validations and their Implementation</title>
      <dc:creator>hannahthesailor</dc:creator>
      <pubDate>Mon, 15 Apr 2024 05:40:55 +0000</pubDate>
      <link>https://dev.to/hannahthesailor/constraints-and-validations-and-their-implementation-3574</link>
      <guid>https://dev.to/hannahthesailor/constraints-and-validations-and-their-implementation-3574</guid>
      <description>&lt;p&gt;When you open an application to the web many users have access to it. These users have the ability to add data that can cause errors, whether it be intentional or unintentional. To handle this we have constraints and validations. These are mechanisms used to ensure that data meets a certain criteria and avoid errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt; - rules defined at SQL level, they set limits or conditions that data must satisfy before it will be stored in the database. Some frequently used constraints are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Primary Key Constraint&lt;/strong&gt;: Ensures that each row in a table has a unique identifier.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Persons (&lt;br&gt;
    ID int NOT NULL,&lt;br&gt;
    LastName varchar(255) NOT NULL,&lt;br&gt;
    FirstName varchar(255),&lt;br&gt;
    Age int,&lt;br&gt;
    PRIMARY KEY (ID)&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Foreign Key Constraint&lt;/strong&gt;: Specifies that the key can only contain values that are in the referenced primary key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Orders (&lt;br&gt;
    OrderID int NOT NULL,&lt;br&gt;
    OrderNumber int NOT NULL,&lt;br&gt;
    PersonID int,&lt;br&gt;
    PRIMARY KEY (OrderID),&lt;br&gt;
    FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Unique Constraint&lt;/strong&gt;: Ensures that values in a column or a group of columns are unique across all rows in a table.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Persons (&lt;br&gt;
    ID int NOT NULL UNIQUE,&lt;br&gt;
    LastName varchar(255) NOT NULL,&lt;br&gt;
    FirstName varchar(255),&lt;br&gt;
    Age int&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check Constraint&lt;/strong&gt;: Sets a limit the value range that can be placed in a column. Its usage varies whether it's being implemented on a table or a column&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Persons (&lt;br&gt;
    ID int NOT NULL,&lt;br&gt;
    LastName varchar(255) NOT NULL,&lt;br&gt;
    FirstName varchar(255),&lt;br&gt;
    Age int,&lt;br&gt;
    CHECK (Age&amp;gt;=18)&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Not Null Constraint&lt;/strong&gt;: Specifies that a column cannot contain null values.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE table_name (&lt;br&gt;
    column1 datatype constraint,&lt;br&gt;
    column2 datatype constraint,&lt;br&gt;
    column3 datatype constraint,&lt;br&gt;
    ....&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When code does not satisfy the set constraints it usually results in an error being raised and the data will not be added to the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validations&lt;/strong&gt; - automatic rules or checks at the application level that ensure that the data entered meets a certain criteria. Common types of validations are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Format Validation&lt;/strong&gt;: Enforces that data is in the correct format, commonly used to validate email, phone numbers, ect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Length Validation&lt;/strong&gt;: Checks the length of input data to ensure it falls within acceptable limits.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Range Validation&lt;/strong&gt;: Verifies that numeric values are within a specified range.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Presence Validation&lt;/strong&gt;: Checks that required fields are not empty or null.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Uniqueness Validation&lt;/strong&gt;: Checks that a value is unique within a specific context, often used for setting emails or usernames.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Validations are typically implemented within the application code and prevent invalid data from being persisted to the database. An error message will display to alert the user if the validation is triggered.&lt;/p&gt;

&lt;p&gt;What happens when you don't implement constraints or validations? Without these users can input anything they want throughout the application, such as putting letters where a number input is expected, or worse someone inputing SQL commands that are designed to compromise the application into the input field. Other problems include a poor user experience when not alert arises to inform them why an input may have been unsuccessful or loss of data completely without an error to tell you the data did not persist!&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/AdministratorsGuide/Constraints/ConstraintTypes/ForeignKeyConstraints.htm#:%7E:text=A%20foreign%20key%20constraint%20specifies,existing%20table%20with%20ALTER%20TABLE%20"&gt;https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/AdministratorsGuide/Constraints/ConstraintTypes/ForeignKeyConstraints.htm#:~:text=A%20foreign%20key%20constraint%20specifies,existing%20table%20with%20ALTER%20TABLE%20&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/sql/sql_constraints.asp"&gt;https://www.w3schools.com/sql/sql_constraints.asp&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS, what is it and what does it do for us?</title>
      <dc:creator>hannahthesailor</dc:creator>
      <pubDate>Mon, 05 Feb 2024 03:04:27 +0000</pubDate>
      <link>https://dev.to/hannahthesailor/css-what-is-it-and-what-does-it-do-for-us-4472</link>
      <guid>https://dev.to/hannahthesailor/css-what-is-it-and-what-does-it-do-for-us-4472</guid>
      <description>&lt;p&gt;CSS stands for Cascading Styling Sheets. It is a computer language for describing the layout and presentation of a document written in HTML to your screen or other viewing medium. CSS was first created by Håkon Wium Lie in the mid 1990's while working with Tim Berners-Lee.&lt;/p&gt;

&lt;p&gt;What are the advantages that CSS brings to the word of coding?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;CSS saves time! CSS saves its style definitions (formatting characteristics) in external .css files. With this file separate from the HTML file (which contains its structure and informational content) you can easily change the look and style of your website by changing the external file rather than going within and rewriting the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS allows for faster download times, which enhances the performance of a website overall. CSS achieves this through a variety of means. As mentioned before the CSS file is saved separate from the HTML, this allows the layout to be applied across multiple pages which allows the computer to save the information rather than redownload it each time navigating from page to page. .css files can also be compressed resulting in faster download times. The code is lightweight, few lines equals less time downloading.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lightweight code. You don't need a ton of code to get CSS to do what you want it to do. This makes it beginner friendly, easy to understand, and manipulate. That's one thing that makes CSS so fun! You can easily see the changes and play around with the look of a website to achieve your desired aesthetic.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is an example of how you could modify a paragraphs font. What do you think the code is modifying about the paragraph?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxywwi0wgf3yojjh6nbjw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxywwi0wgf3yojjh6nbjw.png" alt="Example .css" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if we wanted a link to stand out? Show if it's been visited, highlighted, or in use? CSS simplifies this easily!&lt;br&gt;
Here I'll show you,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsg3j1u83o3vc5jtrfej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsg3j1u83o3vc5jtrfej.png" alt="Example .css" width="800" height="70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally if you want to create a text box you just need this short and simple code in .css&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4upsidbb66ih9rzpkodu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4upsidbb66ih9rzpkodu.png" alt="Now you have a box!" width="800" height="81"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.CSS allows for better accessibility. CSS stying can give you your desired look without messing with the structure. It can make it easier for people who need larger text or a grey scale for reading to override the CSS as it does not mess with the semantics and structure of the website.&lt;/p&gt;

&lt;p&gt;These are not the only benefits of using CSS to style your webpages but for now why not try a few simple ones yourself and see what you come up with! Remember to have fun and let your creative side shine!&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
(&lt;a href="https://byby.dev/css-evolution#:%7E:text=CSS%20(Cascading%20Style%20Sheets)%20was,it%20apart%20from%20the%20rest"&gt;https://byby.dev/css-evolution#:~:text=CSS%20(Cascading%20Style%20Sheets)%20was,it%20apart%20from%20the%20rest&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;(&lt;a href="https://www.boia.org/blog/how-css-benefits-accessibility"&gt;https://www.boia.org/blog/how-css-benefits-accessibility&lt;/a&gt;)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
