{"id":3109,"date":"2024-06-24T08:34:36","date_gmt":"2024-06-24T00:34:36","guid":{"rendered":"https:\/\/five.co\/?p=3109"},"modified":"2026-02-25T14:48:24","modified_gmt":"2026-02-25T06:48:24","slug":"sql-insert-timestamp","status":"publish","type":"post","link":"https:\/\/preview-php85.dzine.org\/five\/blog\/sql-insert-timestamp\/","title":{"rendered":"SQL Insert Timestamp: Quick &#038; Easy Explanation"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In this guide, we&#8217;ll walk through everything you need to know about timestamps in SQL. We&#8217;ll cover:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What SQL timestamps are and why they&#8217;re useful<\/li>\n\n\n\n<li>The different types of timestamp data you can use<\/li>\n\n\n\n<li>How to set up tables with timestamp columns<\/li>\n\n\n\n<li>Some best practices for working with timestamps<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">By the time we&#8217;re done, you&#8217;ll be a pro at handling time-related data in your SQL databases. Let&#8217;s dive in!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div style=\"background-color: #001524;\"><hr style=\"height: 5px;\">\n<pre style=\"text-align: center; overflow: hidden; white-space: pre-line;\"><span style=\"color: #f1ebda; background-color: #4588d8; font-size: calc(25px + 0.390625vw);\"><strong>SQL Made Simple - Try Five<\/strong><br><span style=\"font-size: 14pt;\">Five is the Easiest Way to Create, Model and Query a SQL Database<\/span><\/span><\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\" target=\"_blank\" rel=\"noopener\"><button style=\"background-color: #f8b92b; border: none; color: black; padding: 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 18px; cursor: pointer; margin: 4px 2px; border-radius: 5px;\"><strong>Get Started<\/strong><\/button><\/a><br><span style=\"color: #ffffff; font-size: revert;\">___<\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong><span style=\"color: #ffffff; text-decoration: underline;\">Here&#8217;s What You Can Do With Five<\/span><\/strong><\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"color: #ffffff;\">Create and Model a SQL Database \u2705<br>Write or Build SQL Queries \u2705<br>Visualize Queries as Charts or in Dashboards \u2705<br>Add CRUD Permissions to Control Data Access \u2705<br>Host Your Database Online \u2705&nbsp;<\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"color: #f1ebda; background-color: #4588d8;\"><em><strong>&#8220;Five bridges the gap between SQL and the web, <br>allowing me to create full-stack applications almost entirely in SQL&#8221;<\/strong><\/em><\/span><br><span style=\"color: #ffffff;\">&#8211; Crag Jones, Database Administrator (DBA)<\/span><\/p>\n<hr style=\"height: 5px;\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<div class=\"root-eb-toc-cw96d wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-cw96d \"><div class=\"eb-toc-container eb-toc-cw96d  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemcollapsed=\"false\" data-highlight-scroll=\"false\"><div class=\"eb-toc-header\"><h2 class=\"eb-toc-title\">Table of Contents<\/h2><\/div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:2,&quot;content&quot;:&quot;1. SQL Insert Timestamp Basics&quot;,&quot;text&quot;:&quot;1. SQL Insert Timestamp Basics&quot;,&quot;link&quot;:&quot;1-sql-insert-timestamp-basics&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;When Would You Insert Timestamps?&quot;,&quot;text&quot;:&quot;When Would You Insert Timestamps?&quot;,&quot;link&quot;:&quot;when-would-you-insert-timestamps&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;2. Creating Tables with Timestamp Columns&quot;,&quot;text&quot;:&quot;2. Creating Tables with Timestamp Columns&quot;,&quot;link&quot;:&quot;2-creating-tables-with-timestamp-columns&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Basic Table Creation&quot;,&quot;text&quot;:&quot;Basic Table Creation&quot;,&quot;link&quot;:&quot;basic-table-creation&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Explanation&quot;,&quot;text&quot;:&quot;Explanation&quot;,&quot;link&quot;:&quot;explanation&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Configuring Different Timestamp Columns&quot;,&quot;text&quot;:&quot;Configuring Different Timestamp Columns&quot;,&quot;link&quot;:&quot;configuring-different-timestamp-columns&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Why Choose Five for Managing Timestamps in SQL?&quot;,&quot;text&quot;:&quot;Why Choose Five for Managing Timestamps in SQL?&quot;,&quot;link&quot;:&quot;why-choose-five-for-managing-timestamps-in-sql&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Key Features of Five:&quot;,&quot;text&quot;:&quot;Key Features of Five:&quot;,&quot;link&quot;:&quot;key-features-of-five&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Working with SQL in Five&quot;,&quot;text&quot;:&quot;Working with SQL in Five&quot;,&quot;link&quot;:&quot;working-with-sql-in-five&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Create a MySQL Database Visually&quot;,&quot;text&quot;:&quot;Create a MySQL Database Visually&quot;,&quot;link&quot;:&quot;create-a-mysql-database-visually&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Practical Example&quot;,&quot;text&quot;:&quot;Practical Example&quot;,&quot;link&quot;:&quot;practical-example&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;3. Inserting Timestamps into Tables&quot;,&quot;text&quot;:&quot;3. Inserting Timestamps into Tables&quot;,&quot;link&quot;:&quot;3-inserting-timestamps-into-tables&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Using CURRENT_TIMESTAMP&quot;,&quot;text&quot;:&quot;Using CURRENT_TIMESTAMP&quot;,&quot;link&quot;:&quot;using-current_timestamp&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Using Explicit Timestamps&quot;,&quot;text&quot;:&quot;Using Explicit Timestamps&quot;,&quot;link&quot;:&quot;using-explicit-timestamps&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Updating Timestamps&quot;,&quot;text&quot;:&quot;Updating Timestamps&quot;,&quot;link&quot;:&quot;updating-timestamps&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Practical Scenarios&quot;,&quot;text&quot;:&quot;Practical Scenarios&quot;,&quot;link&quot;:&quot;practical-scenarios&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;FAQ&quot;,&quot;text&quot;:&quot;FAQ&quot;,&quot;link&quot;:&quot;faq&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;What is a timestamp in SQL?&quot;,&quot;text&quot;:&quot;What is a timestamp in SQL?&quot;,&quot;link&quot;:&quot;what-is-a-timestamp-in-sql&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;How do you insert the current timestamp in SQL?&quot;,&quot;text&quot;:&quot;How do you insert the current timestamp in SQL?&quot;,&quot;link&quot;:&quot;how-do-you-insert-the-current-timestamp-in-sql&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Can I automatically add a timestamp when a row is created?&quot;,&quot;text&quot;:&quot;Can I automatically add a timestamp when a row is created?&quot;,&quot;link&quot;:&quot;can-i-automatically-add-a-timestamp-when-a-row-is-created&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;What\\u2019s the difference between TIMESTAMP and DATETIME?&quot;,&quot;text&quot;:&quot;What\\u2019s the difference between TIMESTAMP and DATETIME?&quot;,&quot;link&quot;:&quot;whats-the-difference-between-timestamp-and-datetime&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;When should you use timestamps in a database?&quot;,&quot;text&quot;:&quot;When should you use timestamps in a database?&quot;,&quot;link&quot;:&quot;when-should-you-use-timestamps-in-a-database&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;1. SQL Insert Timestamp Basics&quot;,&quot;value&quot;:&quot;1-sql-insert-timestamp-basics&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;When Would You Insert Timestamps?&quot;,&quot;value&quot;:&quot;when-would-you-insert-timestamps&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;2. Creating Tables with Timestamp Columns&quot;,&quot;value&quot;:&quot;2-creating-tables-with-timestamp-columns&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Basic Table Creation&quot;,&quot;value&quot;:&quot;basic-table-creation&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Explanation&quot;,&quot;value&quot;:&quot;explanation&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Configuring Different Timestamp Columns&quot;,&quot;value&quot;:&quot;configuring-different-timestamp-columns&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Why Choose Five for Managing Timestamps in SQL?&quot;,&quot;value&quot;:&quot;why-choose-five-for-managing-timestamps-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Key Features of Five:&quot;,&quot;value&quot;:&quot;key-features-of-five&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Working with SQL in Five&quot;,&quot;value&quot;:&quot;working-with-sql-in-five&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Create a MySQL Database Visually&quot;,&quot;value&quot;:&quot;create-a-mysql-database-visually&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Practical Example&quot;,&quot;value&quot;:&quot;practical-example&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;3. Inserting Timestamps into Tables&quot;,&quot;value&quot;:&quot;3-inserting-timestamps-into-tables&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Using CURRENT_TIMESTAMP&quot;,&quot;value&quot;:&quot;using-current_timestamp&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Using Explicit Timestamps&quot;,&quot;value&quot;:&quot;using-explicit-timestamps&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Updating Timestamps&quot;,&quot;value&quot;:&quot;updating-timestamps&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Practical Scenarios&quot;,&quot;value&quot;:&quot;practical-scenarios&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;FAQ&quot;,&quot;value&quot;:&quot;faq&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;What is a timestamp in SQL?&quot;,&quot;value&quot;:&quot;what-is-a-timestamp-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;How do you insert the current timestamp in SQL?&quot;,&quot;value&quot;:&quot;how-do-you-insert-the-current-timestamp-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Can I automatically add a timestamp when a row is created?&quot;,&quot;value&quot;:&quot;can-i-automatically-add-a-timestamp-when-a-row-is-created&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;What\\u2019s the difference between TIMESTAMP and DATETIME?&quot;,&quot;value&quot;:&quot;whats-the-difference-between-timestamp-and-datetime&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;When should you use timestamps in a database?&quot;,&quot;value&quot;:&quot;when-should-you-use-timestamps-in-a-database&quot;,&quot;isDelete&quot;:false}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class=\"eb-toc__list\"><li><a href=\"#1-sql-insert-timestamp-basics\">1. SQL Insert Timestamp Basics<\/a><li><a href=\"#when-would-you-insert-timestamps\">When Would You Insert Timestamps?<\/a><li><a href=\"#2-creating-tables-with-timestamp-columns\">2. Creating Tables with Timestamp Columns<\/a><ul class=\"eb-toc__list\"><li><a href=\"#basic-table-creation\">Basic Table Creation<\/a><li><a href=\"#explanation\">Explanation<\/a><li><a href=\"#configuring-different-timestamp-columns\">Configuring Different Timestamp Columns<\/a><li><a href=\"#why-choose-five-for-managing-timestamps-in-sql\">Why Choose Five for Managing Timestamps in SQL?<\/a><ul class=\"eb-toc__list\"><li><a href=\"#key-features-of-five\">Key Features of Five:<\/a><li><a href=\"#working-with-sql-in-five\">Working with SQL in Five<\/a><li><a href=\"#create-a-mysql-database-visually\">Create a MySQL Database Visually<\/a><li><a href=\"#practical-example\">Practical Example<\/a><\/li><\/ul><\/li><\/ul><li><a href=\"#3-inserting-timestamps-into-tables\">3. Inserting Timestamps into Tables<\/a><ul class=\"eb-toc__list\"><li><a href=\"#using-current_timestamp\">Using CURRENT_TIMESTAMP<\/a><li><a href=\"#using-explicit-timestamps\">Using Explicit Timestamps<\/a><li><a href=\"#updating-timestamps\">Updating Timestamps<\/a><li><a href=\"#practical-scenarios\">Practical Scenarios<\/a><\/li><\/ul><li><a href=\"#faq\">FAQ<\/a><ul class=\"eb-toc__list\"><li><a href=\"#what-is-a-timestamp-in-sql\">What is a timestamp in SQL?<\/a><li><a href=\"#how-do-you-insert-the-current-timestamp-in-sql\">How do you insert the current timestamp in SQL?<\/a><li><a href=\"#can-i-automatically-add-a-timestamp-when-a-row-is-created\">Can I automatically add a timestamp when a row is created?<\/a><li><a href=\"#whats-the-difference-between-timestamp-and-datetime\">What\u2019s the difference between TIMESTAMP and DATETIME?<\/a><li><a href=\"#when-should-you-use-timestamps-in-a-database\">When should you use timestamps in a database?<\/a><\/li><\/ul><\/ul><\/div><\/div><\/div><\/div><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. SQL Insert Timestamp Basics<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In SQL, a timestamp is a data type that stores both date and time information. Here are the key timestamp-related data types you&#8217;ll encounter:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>TIMESTAMP<\/strong>: Stores date and time with high precision<\/li>\n\n\n\n<li><strong>DATETIME<\/strong>: Similar to TIMESTAMP but with some key differences<\/li>\n\n\n\n<li><strong>DATE<\/strong>: For when you only need to store the date<\/li>\n\n\n\n<li><strong>TIME<\/strong>: For storing just the time of day<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Each of these SQL timestamp types has its own use cases, which we&#8217;ll explore in depth throughout this guide.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">When Would You Insert Timestamps?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Tracking Record Creation and Modification<\/strong>: Timestamps help you know when a record was created or last modified, which is essential for audit trails and version control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Logging Events<\/strong>: In applications where logging is crucial, such as error tracking or activity logs, timestamps provide a clear record of when each event occurred.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scheduling and Time Management<\/strong>: Applications that involve scheduling, such as booking systems or project management tools, rely on accurate timestamp data to function correctly.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Creating Tables with Timestamp Columns<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, we&#8217;ll dive into creating tables that include timestamp columns in SQL. Timestamps are crucial for tracking when records are created or updated, and they provide valuable insights into the data&#8217;s history and changes. We&#8217;ll cover the SQL syntax for adding timestamp columns and explain the different configurations you can use.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Basic Table Creation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To create a table with timestamp columns, you&#8217;ll need to use the appropriate data type, such as <code>TIMESTAMP<\/code> or <code>DATETIME<\/code>. Here&#8217;s an example of how to create a table with both a creation timestamp and an update timestamp:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE example_table (\n    id INT PRIMARY KEY,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">example_table<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    created_at <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    updated_at <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP <\/span><span style=\"color: #C678DD\">ON<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>id<\/code>: A primary key with auto-increment.<\/li>\n\n\n\n<li><code>product_name<\/code>: A column to store the product name.<\/li>\n\n\n\n<li><code>quantity<\/code>: A column to store the quantity sold.<\/li>\n\n\n\n<li><code>price<\/code>: A column to store the price of the product.<\/li>\n\n\n\n<li><code>created_at<\/code>: A timestamp column that automatically sets to the current timestamp when the record is created.<\/li>\n\n\n\n<li><code>updated_at<\/code>: A timestamp column that sets to the current timestamp when the record is created and updates to the current timestamp whenever the record is modified.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Explanation<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>TIMESTAMP Data Type<\/strong>: The <code>TIMESTAMP<\/code> data type stores both date and time information. It is highly precise and automatically updates based on certain conditions.<\/li>\n\n\n\n<li><strong>DEFAULT CURRENT_TIMESTAMP<\/strong>: This clause sets the default value of the column to the current timestamp at the time the record is created.<\/li>\n\n\n\n<li><strong>ON UPDATE CURRENT_TIMESTAMP<\/strong>: This clause automatically updates the column to the current timestamp whenever the record is modified.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Configuring Different Timestamp Columns<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on your requirements, you might need different configurations for your timestamp columns. Here are a few variations:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Single Timestamp for Creation Only<\/strong>: <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE user_sessions (\n    session_id INT PRIMARY KEY AUTO_INCREMENT,\n    user_id INT,\n    session_start TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">user_sessions<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    session_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\"> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    user_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    session_start <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration is useful for tracking the start time of user sessions without worrying about updates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Separate Columns for Date and Time<\/strong>: <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE appointments (\n    appointment_id INT PRIMARY KEY AUTO_INCREMENT,\n    appointment_date DATE,\n    appointment_time TIME,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">appointments<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    appointment_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\"> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    appointment_date <\/span><span style=\"color: #C678DD\">DATE<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    appointment_time <\/span><span style=\"color: #C678DD\">TIME<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    created_at <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This approach separates the date and time into different columns, which can be useful for applications that need to handle them independently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Using DATETIME Instead of TIMESTAMP<\/strong>: <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE orders (\n    order_id INT PRIMARY KEY AUTO_INCREMENT,\n    order_date DATETIME DEFAULT CURRENT_TIMESTAMP,\n    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">orders<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    order_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\"> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    order_date <\/span><span style=\"color: #C678DD\">DATETIME<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    updated_at <\/span><span style=\"color: #C678DD\">DATETIME<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP <\/span><span style=\"color: #C678DD\">ON<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DATETIME<\/code> is similar to <code>TIMESTAMP<\/code> but does not automatically adjust for time zone changes.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Why Choose Five for Managing Timestamps in SQL?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integrating Five with your SQL operations, especially for managing timestamps, offers a powerful and efficient solution for developing modern, data-driven business applications. Five is designed to simplify database management and web application development, making it accessible to even junior developers. Here\u2019s why you should consider using Five for handling your SQL timestamps alongside your other development needs:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Key Features of Five:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Build<\/strong>: Develop applications locally at no cost with Five\u2019s full-featured environment. This allows you to experiment and refine your database structures, including timestamp configurations, without any initial investment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Deploy<\/strong>: Deploy applications to a secure and scalable cloud infrastructure. Five makes it easy to manage your applications in a production environment, ensuring high availability and security for your data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Working with SQL in Five<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Five provides an easy environment to work with <a href=\"https:\/\/preview-php85.dzine.org\/five\/blog\/how-to-create-a-front-end-for-a-mysql-database\/\">SQL databases<\/a>, offering both visual and coding tools to suit your preferences. Here\u2019s how Five can help you manage timestamps efficiently:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create a MySQL Database Visually<\/h4>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img width=\"1024\" height=\"477\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/10\/database-modeler-1024x477.png\" alt=\"Five.Co - Database Modeler - Manage Databases Visually\" class=\"wp-image-1990\" style=\"width:839px;height:auto\" srcset=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/10\/database-modeler-1024x477.png 1024w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/10\/database-modeler-300x140.png 300w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/10\/database-modeler-768x358.png 768w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/10\/database-modeler-1536x715.png 1536w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/10\/database-modeler.png 1858w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">With Five\u2019s visual database builder, you can <a href=\"https:\/\/help.five.org\/2.1\/docs\/tables\/add-table\/\" rel=\"nofollow noopener\" target=\"_blank\">create tables<\/a>, define fields, set primary and foreign keys, and establish <a href=\"https:\/\/preview-php85.dzine.org\/five\/blog\/how-to-create-many-to-many-relationships-in-sql\/\">relationships<\/a> with just a few clicks. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img width=\"1280\" height=\"720\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2023\/03\/Five.Co-Code-Editor.png\" alt=\"Five.Co - Code Editor\" class=\"wp-image-866\" style=\"width:748px;height:auto\"\/><\/figure>\n<\/div>\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Five\u2019s SQL editor allows you to write SELECT, JOIN, and UPDATE statements directly or use its visual query builder. This flexibility ensures you can perform any database operation efficiently, whether you prefer coding or visual tools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;The only way to learn a new programming language is by writing programs in it.&#8221; &#8211; Dennis Ritchie, Creator of the C Programming Language. We&#8217;d go even further and say that the best way to learn is by building a real and functional application, and Five makes this possible.<\/p>\n\n\n\n<div style=\"background-color: #001524;\"><hr style=\"height: 5px;\" \/>\n<pre style=\"text-align: center; overflow: hidden; white-space: pre-line;\"><span style=\"color: #f1ebda; background-color: #4588d8; font-size: calc(18px + 0.390625vw);\"><strong>Go From SQL Database to Web App<\/strong><br \/><span style=\"font-size: 14pt;\">Start Developing<\/span><\/span><\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\" target=\"_blank\" rel=\"noopener\"><button style=\"background-color: #f8b92b; border: none; color: black; padding: 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 18px; cursor: pointer; margin: 4px 2px; border-radius: 5px;\"><strong>Get Instant Access<\/strong><\/button><br \/><\/a><\/p>\n<hr style=\"height: 5px;\" \/><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Practical Example<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say you run an online store and want to track your sales. You need to know when each sale was made and when any changes were made to the sale record. Here&#8217;s how you could set up your table:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE online_sales (\n    sale_id INT PRIMARY KEY AUTO_INCREMENT,\n    product_id INT,\n    quantity_sold INT,\n    sale_price DECIMAL(10, 2),\n    sale_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n    last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">online_sales<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    sale_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\"> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    product_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    quantity_sold <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    sale_price <\/span><span style=\"color: #C678DD\">DECIMAL<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">10<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    sale_date <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    last_modified <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP <\/span><span style=\"color: #C678DD\">ON<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">With this table structure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Each sale record is uniquely identified by <code>sale_id<\/code>.<\/li>\n\n\n\n<li>The <code>sale_date<\/code> column automatically captures the date and time of the sale.<\/li>\n\n\n\n<li>The <code>last_modified<\/code> column updates automatically whenever any changes are made to the record, providing an accurate audit trail.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In the next section, we will explore how to insert timestamp data into your tables effectively.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Inserting Timestamps into Tables<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Inserting timestamps into tables is a crucial part of managing your database records. Timestamps can be inserted automatically using SQL functions or manually for specific data entries. This section will cover both methods: using <code>CURRENT_TIMESTAMP<\/code> for automatic insertion and inserting explicit timestamps manually.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Using <code>CURRENT_TIMESTAMP<\/code><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>CURRENT_TIMESTAMP<\/code> function is a convenient way to automatically insert the current date and time into a timestamp column. This is useful for tracking when records are created or updated without having to manually enter the date and time each time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example: Automatic Insertion with <code>CURRENT_TIMESTAMP<\/code><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s revisit the <code>sales_records<\/code> table from the previous section. When inserting a new record, the <code>created_at<\/code> and <code>updated_at<\/code> columns will automatically set to the current timestamp.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"INSERT INTO sales_records (product_name, quantity, price) \nVALUES ('Product A', 10, 29.99);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">INSERT INTO<\/span><span style=\"color: #ABB2BF\"> sales_records (product_name, quantity, price) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">VALUES<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #98C379\">&#39;Product A&#39;<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">10<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">29<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">99<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>created_at<\/code> column automatically captures the timestamp when the record is inserted.<\/li>\n\n\n\n<li>The <code>updated_at<\/code> column also captures the current timestamp and will update automatically whenever the record is modified.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>DEFAULT CURRENT_TIMESTAMP<\/code> clause ensures that the <code>created_at<\/code> column records the current time at the moment of insertion.<\/li>\n\n\n\n<li>The <code>ON UPDATE CURRENT_TIMESTAMP<\/code> clause updates the <code>updated_at<\/code> column to the current time whenever the record is updated.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Using Explicit Timestamps<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In some cases, you might need to insert specific timestamps into your tables rather than using the current timestamp. This is useful for backdating entries or importing data with historical timestamps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example: Manual Insertion of Specific Timestamps<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you need to insert a record with a specific creation time and update time into the <code>sales_records<\/code> table.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"INSERT INTO sales_records (product_name, quantity, price, created_at, updated_at) \nVALUES ('Product B', 5, 49.99, '2024-06-24 12:34:56', '2024-06-24 12:34:56');\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">INSERT INTO<\/span><span style=\"color: #ABB2BF\"> sales_records (product_name, quantity, price, created_at, updated_at) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">VALUES<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #98C379\">&#39;Product B&#39;<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">5<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">49<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">99<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;2024-06-24 12:34:56&#39;<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;2024-06-24 12:34:56&#39;<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Both <code>created_at<\/code> and <code>updated_at<\/code> are set to &#8216;2024-06-24 12:34:56&#8217;.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Manually entering the timestamp values allows you to specify exact dates and times for record creation and updates.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Updating Timestamps<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Timestamps can also be updated when records are modified. SQL provides mechanisms to automatically update timestamps using the <code>ON UPDATE CURRENT_TIMESTAMP<\/code> clause or manually by setting the timestamp explicitly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example: Automatic Update of <code>updated_at<\/code> Column<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>updated_at<\/code> column in the <code>sales_records<\/code> table will automatically update to the current timestamp whenever the record is modified.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"UPDATE sales_records \nSET price = 24.99 \nWHERE product_name = 'Product A';\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> sales_records <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> price <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">24<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">99<\/span><span style=\"color: #ABB2BF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">WHERE<\/span><span style=\"color: #ABB2BF\"> product_name <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;Product A&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>updated_at<\/code> column automatically updates to the current timestamp because of the <code>ON UPDATE CURRENT_TIMESTAMP<\/code> clause.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example: Manual Update of Timestamps<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also manually set the <code>updated_at<\/code> column to a specific timestamp when updating a record.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"UPDATE sales_records \nSET price = 24.99, updated_at = '2024-06-25 10:00:00' \nWHERE product_name = 'Product B';\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> sales_records <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> price <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">24<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">99<\/span><span style=\"color: #ABB2BF\">, updated_at <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;2024-06-25 10:00:00&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">WHERE<\/span><span style=\"color: #ABB2BF\"> product_name <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;Product B&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>updated_at<\/code> column is manually set to &#8216;2024-06-25 10:00:00&#8217;.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Practical Scenarios<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scenario 1: Tracking Order Dates<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For an e-commerce application, it&#8217;s important to track when orders are placed and when they are shipped. Here&#8217;s how you can manage these timestamps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Creating the Orders Table:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE orders (\n    order_id INT PRIMARY KEY AUTO_INCREMENT,\n    customer_id INT,\n    order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n    shipped_date TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">orders<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    order_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\"> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    customer_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    order_date <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    shipped_date <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Inserting Orders:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"INSERT INTO orders (customer_id, order_date, shipped_date) \nVALUES (123, CURRENT_TIMESTAMP, NULL);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">INSERT INTO<\/span><span style=\"color: #ABB2BF\"> orders (customer_id, order_date, shipped_date) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">VALUES<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #D19A66\">123<\/span><span style=\"color: #ABB2BF\">, CURRENT_TIMESTAMP, <\/span><span style=\"color: #C678DD\">NULL<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Updating Shipped Date:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"UPDATE orders \nSET shipped_date = '2024-06-26 15:00:00' \nWHERE order_id = 1;\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> orders <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> shipped_date <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;2024-06-26 15:00:00&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">WHERE<\/span><span style=\"color: #ABB2BF\"> order_id <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scenario 2: Logging User Activity<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a web application, logging user activity with precise timestamps can help monitor user behavior and system performance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Creating the Activity Log Table:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"CREATE TABLE activity_log (\n    log_id INT PRIMARY KEY AUTO_INCREMENT,\n    user_id INT,\n    activity VARCHAR(255),\n    activity_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">activity_log<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    log_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\"> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    user_id <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    activity <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">255<\/span><span style=\"color: #ABB2BF\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    activity_timestamp <\/span><span style=\"color: #C678DD\">TIMESTAMP<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> CURRENT_TIMESTAMP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Inserting Activity Logs:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"INSERT INTO activity_log (user_id, activity) \nVALUES (456, 'User logged in');\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">INSERT INTO<\/span><span style=\"color: #ABB2BF\"> activity_log (user_id, activity) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">VALUES<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #D19A66\">456<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;User logged in&#39;<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Querying Recent Activities:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT * FROM activity_log \nWHERE activity_timestamp &gt; '2024-06-24 00:00:00';\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> * <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> activity_log <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">WHERE<\/span><span style=\"color: #ABB2BF\"> activity_timestamp <\/span><span style=\"color: #56B6C2\">&gt;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;2024-06-24 00:00:00&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Inserting timestamps into your SQL tables, whether automatically using <code>CURRENT_TIMESTAMP<\/code> or manually for specific records, is essential for accurate data tracking and management.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<ol class=\"rank-math-list \">\n<li id=\"faq-question-1771985858796\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong>What is a timestamp in SQL?<\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A timestamp is a date-and-time value stored in a database that records when an event occurred, such as when a row was created or updated. It\u2019s commonly used for logging, auditing, and tracking changes over time.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771985909936\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong>How do you insert the current timestamp in SQL?<\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can insert the current date and time using built-in functions like <code>CURRENT_TIMESTAMP<\/code> (or <code>NOW()<\/code> in some databases) within your <code>INSERT<\/code> statement to automatically capture the exact time of the operation.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771985985770\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong>Can I automatically add a timestamp when a row is created?<\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes. You can set a column\u2019s default value to <code>CURRENT_TIMESTAMP<\/code>, which automatically records the creation time whenever a new row is inserted without needing to specify it manually.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771985994514\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong>What\u2019s the difference between TIMESTAMP and DATETIME?<\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>While both store date and time, <code>TIMESTAMP<\/code> often handles time zones and can auto-update depending on the database, whereas <code>DATETIME<\/code> typically stores the value exactly as provided without automatic conversions. Choosing between them depends on your use case and database system.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771986003404\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong>When should you use timestamps in a database?<\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Timestamps are useful for tracking events such as record creation, updates, user actions, or system logs. They help with auditing, debugging, and performing time-based analysis on your data.<\/p>\n\n<\/div>\n<\/li>\n<\/ol>\n<\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we&#8217;ll walk through everything you need to know about timestamps in SQL. We&#8217;ll cover: By the time we&#8217;re done, you&#8217;ll be a pro at handling time-related data in your SQL databases. Let&#8217;s dive in! SQL Made Simple &#8211; Try FiveFive is the Easiest Way to Create, Model and Query a SQL Database [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":3119,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":true,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-3109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation.png",1280,720,false],"thumbnail":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation-150x150.png",150,150,true],"medium":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation-300x169.png",300,169,true],"medium_large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation-768x432.png",768,432,true],"large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation-1024x576.png",1024,576,true],"1536x1536":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation.png",1280,720,false],"2048x2048":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-SQL-Insert-Timestamp-Quick-Easy-Explanation.png",1280,720,false]},"uagb_author_info":{"display_name":"Ryan Forrester","author_link":"https:\/\/preview-php85.dzine.org\/five\/author\/f1v5_ed9_au\/"},"uagb_comment_info":0,"uagb_excerpt":"In this guide, we&#8217;ll walk through everything you need to know about timestamps in SQL. We&#8217;ll cover: By the time we&#8217;re done, you&#8217;ll be a pro at handling time-related data in your SQL databases. Let&#8217;s dive in! SQL Made Simple - Try FiveFive is the Easiest Way to Create, Model and Query a SQL Database&hellip;","_links":{"self":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/comments?post=3109"}],"version-history":[{"count":0,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3109\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media\/3119"}],"wp:attachment":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media?parent=3109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/categories?post=3109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/tags?post=3109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}