One place for hosting & domains

      Update

      How To Update Data in SQL


      Introduction

      When working with a database, there may be times when you need to change data that’s already been inserted into it. For example, you may need to correct a misspelled entry or perhaps you have new information to add to an incomplete record. Structured Query Language — more commonly known as SQL — provides the UPDATE keyword which allows users to change existing data in a table.

      This guide outlines how you can use SQL’s UPDATE syntax to change data in one or more tables. It also explains how SQL handles UPDATE operations that conflict with foreign key constraints.

      Prerequisites

      To follow this guide, you’ll need a computer running some type of relational database management system (RDBMS) that uses SQL. The instructions and examples in this guide were validated using the following environment:

      Note: Please note that many RDBMSs use their own unique implementations of SQL. Although the commands outlined in this tutorial will work on most RDBMSs, the exact syntax or output may differ if you test them on a system other than MySQL.

      • You’ll also need a database with some tables loaded with sample data which you can use to practice updating SQL data. We encourage you to go through the following Connecting to MySQL and Setting up a Sample Database section for details on how to connect to a MySQL server and create the testing database used in examples throughout this guide.

      Connecting To MySQL and Setting Up a Sample Database

      If your SQL database system runs on a remote server, SSH into your server from your local machine:

      Then open up the MySQL server prompt, replacing sammy with the name of your MySQL user account:

      Create a database named updateDB:

      • CREATE DATABASE updateDB;

      If the database was created successfully, you’ll receive output like this:

      Output

      Query OK, 1 row affected (0.01 sec)

      To select the updateDB database, run the following USE statement:

      Output

      Database changed

      After selecting the updateDB database, create a couple tables within it. For the examples used in this guide, imagine that you run a talent agency and have decided to begin tracking your clients and their performances in an SQL database. You plan to start off with two tables, the first of which will store information about your clients. You decide this table needs four columns:

      • clientID: each client’s identification number, expressed with the int data type. This column will also serve as the table’s primary key, with each value functioning as a unique identifier for its respective row
      • name: each client’s name, expressed using the varchar data type with a maximum of 20 characters
      • routine: a brief description of each client’s primary performance genre, again expressed using the varchar data type but with a maximum of 30 characters
      • performanceFee: a column to record each client’s standard performance fee, it uses the decimal data type with any values in this column limited to a maximum of five digits in length with two of those digits to the right of the decimal point. Thus, the range of values allowed in this column goes from -999.99 to 999.99

      Create a table named clients that has these four columns:

      • CREATE TABLE clients
      • (clientID int PRIMARY KEY,
      • name varchar(20),
      • routine varchar(30),
      • standardFee decimal (5,2)
      • );

      The second table will store information about your clients’ performances at a local venue. You decide this table needs five columns:

      • showID: similar to the clientID column, this column will hold a unique identification number for each show, expressed with the int data type. Likewise this column will serve as primary key for the shows table
      • showDate: the date of each performance. This column’s values are expressed using the date data type which uses the 'YYYY-MM-DD' format
      • clientID: the ID number of the client performing at the show, expressed as an integer
      • attendance: the number of attendees at each performance, expressed as an integer
      • ticketPrice: the price of an individual ticket at each show. This column uses the decimal data type with any values in this column limited to a maximum of four digits in length with two of those digits to the right of the decimal point, so the range of values allowed in this column is -99.99 to 99.99

      To ensure that the clientID column only holds values that represent valid client ID numbers, you decide to apply a foreign key constraint to the clientID column that references the clients table’s clientID column. A foreign key constraint is a way to express a relationship between two tables by requiring that values in the column on which it applies must already exist in the column that it references. In the following example, the FOREIGN KEY constraint requires that any value added to the clientID column in the shows table must already exist in the client table’s clientID column.

      Create a table named clients that has these five columns:

      • CREATE TABLE shows
      • (showID int PRIMARY KEY,
      • showDate date,
      • clientID int,
      • attendance int,
      • ticketPrice decimal (4,2),
      • CONSTRAINT client_fk
      • FOREIGN KEY (clientID)
      • REFERENCES clients(clientID)
      • );

      Note that this example provides a name for the foreign key constraint: client_fk. MySQL will automatically generate a name for any constraint you add, but defining one here will be useful when we need to reference this constraint later on.

      Next, run the following INSERT INTO statement to load the clients table with five rows of sample data:

      • INSERT INTO clients
      • VALUES
      • (1, 'Gladys', 'song and dance', 180),
      • (2, 'Catherine', 'standup', 99.99),
      • (3, 'Georgeanna', 'standup', 45),
      • (4, 'Wanda', 'song and dance', 200),
      • (5, 'Ann', 'trained squirrel', 79.99);

      Then run another INSERT INTO statement to load the shows table with ten rows of sample data:

      • INSERT INTO shows
      • VALUES
      • (1, '2019-12-25', 4, 124, 15),
      • (2, '2020-01-11', 5, 84, 29.50),
      • (3, '2020-01-17', 3, 170, 12.99),
      • (4, '2020-01-31', 5, 234, 14.99),
      • (5, '2020-02-08', 1, 86, 25),
      • (6, '2020-02-14', 3, 102, 39.5),
      • (7, '2020-02-15', 2, 101, 26.50),
      • (8, '2020-02-27', 2, 186, 19.99),
      • (9, '2020-03-06', 4, 202, 30),
      • (10, '2020-03-07', 5, 250, 8.99);

      With that, you’re ready to follow the rest of the guide and begin learning about how to update data with SQL.

      Updating Data in a Single Table

      The general syntax of an UPDATE statement looks like this:

      • UPDATE table_name
      • SET column_name = value_expression
      • WHERE conditions_apply;

      Following the UPDATE keyword is the name of the table storing the data you want to update. After that is a SET clause which specifies which column’s data should be updated and how. Think of the SET clause as setting values in the specified column as equal to whatever value expression you provide.

      In SQL, a value expression — sometimes known as a scalar expression — is any expression that will return a single value for every row to be updated. This could be a string literal, or a mathematical operation performed on existing numeric values in the column. You must include at least one value assignment in every UPDATE statement, but you can include more than one to update data in multiple columns.

      After the SET clause is a WHERE clause. Including a WHERE clause in an UPDATE statement like in this example syntax allows you to filter out any rows that you don’t want to update. A WHERE clause is entirely optional in UPDATE statements, but if you don’t include one the operation will update every row in the table.

      To illustrate how SQL handles UPDATE operations, start by taking a look at all the data in the clients table. The following query includes an asterisk (*) which is SQL shorthand representing every column in the table, so this query will return all the data from every column in the clients table:

      Output

      +----------+------------+------------------+-------------+ | clientID | name | routine | standardFee | +----------+------------+------------------+-------------+ | 1 | Gladys | song and dance | 180.00 | | 2 | Catherine | standup | 99.99 | | 3 | Georgeanna | standup | 45.00 | | 4 | Wanda | song and dance | 200.00 | | 5 | Ann | trained squirrel | 79.99 | +----------+------------+------------------+-------------+ 5 rows in set (0.00 sec)

      Say, for example, that you notice Katherine’s name is misspelled — it should begin with a “K” but in the table it begins with a “C” — so you decide to change that value by running the following UPDATE statement. This operation updates values in the name column by changing the name value of any row with the name Catherine to Katherine:

      • UPDATE clients
      • SET name="Katherine"
      • WHERE name="Catherine";

      Output

      Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0

      This output indicates that only one row was updated. You can confirm this by running the previous SELECT query again:

      Output

      +----------+------------+------------------+-------------+ | clientID | name | routine | standardFee | +----------+------------+------------------+-------------+ | 1 | Gladys | song and dance | 180.00 | | 2 | Katherine | standup | 99.99 | | 3 | Georgeanna | standup | 45.00 | | 4 | Wanda | song and dance | 200.00 | | 5 | Ann | trained squirrel | 79.99 | +----------+------------+------------------+-------------+ 5 rows in set (0.00 sec)

      This output shows that the value formerly reading Catherine has indeed been changed to Katherine.

      This example updated only one value in the name column. However, you can update multiple values with a less exclusive WHERE clause.

      To illustrate, imagine that you negotiate standard performance fees for all your clients who perform stand-up comedy or song and dance routines. The following statement will update values in the standardFee column by setting them equal to 140.

      Note that this example’s WHERE clause includes a LIKE operator so it only updates the performanceFee value for each client whose routine value matches the specified wildcard pattern, 's%'. In other words, it will update the performance fee of any performer whose routine starts with the letter “s”:

      • UPDATE clients
      • SET standardFee = 140
      • WHERE routine LIKE 's%';

      Output

      Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0

      If you query the contents of the clients table once again, the result set will confirm that four of your clients now have the same performance fee:

      Output

      +----------+------------+------------------+-------------+ | clientID | name | routine | standardFee | +----------+------------+------------------+-------------+ | 1 | Gladys | song and dance | 140.00 | | 2 | Katherine | standup | 140.00 | | 3 | Georgeanna | standup | 140.00 | | 4 | Wanda | song and dance | 140.00 | | 5 | Ann | trained squirrel | 79.99 | +----------+------------+------------------+-------------+ 5 rows in set (0.00 sec)

      If any columns in your table hold numeric values, you can update them using an arithmetic operation in the SET clause. To illustrate, say that you also negotiate a forty percent increase for each of your clients’ performance fees. To reflect this in the clients table, you could run an UPDATE operation like this:

      • UPDATE clients
      • SET standardFee = standardFee * 1.4;

      Output

      Query OK, 5 rows affected, 1 warning (0.00 sec) Rows matched: 5 Changed: 5 Warnings: 1

      Note: Notice that this output indicates the update resulted in a warning. Oftentimes, MySQL will issue a warning when it’s forced to make a change to your data because of a column or table’s definition.

      MySQL provides the SHOW WARNINGS shortcut that can help explain any warnings you receive:

      Output

      +-------+------+--------------------------------------------------+ | Level | Code | Message | +-------+------+--------------------------------------------------+ | Note | 1265 | Data truncated for column 'standardFee' at row 5 | +-------+------+--------------------------------------------------+ 1 row in set (0.00 sec)

      This output informs us that the database system issued the warning because it had to truncate one of the new standardFee values so it would conform to the decimal format — five digits with two to the right of the decimal point — defined previously.

      Query the clients table once more to confirm that each of the clients’ performance fees have increased by forty percent.

      Output

      +----------+------------+------------------+-------------+ | clientID | name | routine | standardFee | +----------+------------+------------------+-------------+ | 1 | Gladys | song and dance | 196.00 | | 2 | Katherine | standup | 196.00 | | 3 | Georgeanna | standup | 196.00 | | 4 | Wanda | song and dance | 196.00 | | 5 | Ann | trained squirrel | 111.99 | +----------+------------+------------------+-------------+ 5 rows in set (0.00 sec)

      As mentioned previously, you can also update data in multiple columns with a single UPDATE statement. To do this, you must specify every column you want to update, following each with the respective value expression, and then separate each column and value expression pair with a comma.

      For example, say that you learn that the venue where your clients perform had misreported the number of attendees for all of Georgeanna and Wanda’s shows. By coincidence, you also happened to enter the wrong ticket price for each of their performances.

      Before updating the data in the shows table, run the following query to retrieve all the data currently held within it:

      Output

      +--------+------------+----------+------------+-------------+ | showID | showDate | clientID | attendance | ticketPrice | +--------+------------+----------+------------+-------------+ | 1 | 2019-12-25 | 4 | 124 | 15.00 | | 2 | 2020-01-11 | 5 | 84 | 29.50 | | 3 | 2020-01-17 | 3 | 170 | 12.99 | | 4 | 2020-01-31 | 5 | 234 | 14.99 | | 5 | 2020-02-08 | 1 | 86 | 25.00 | | 6 | 2020-02-14 | 3 | 102 | 39.50 | | 7 | 2020-02-15 | 2 | 101 | 26.50 | | 8 | 2020-02-27 | 2 | 186 | 19.99 | | 9 | 2020-03-06 | 4 | 202 | 30.00 | | 10 | 2020-03-07 | 5 | 250 | 8.99 | +--------+------------+----------+------------+-------------+ 10 rows in set (0.01 sec)

      To reflect the actual numbers and prices, you update the table to add twenty attendees to each of their performances and increase each of their ticketPrice values by fifty percent. You could do so with an operation like the following:

      • UPDATE shows
      • SET attendance = attendance + 20,
      • ticketPrice = ticketPrice * 1.5
      • WHERE clientID IN
      • (SELECT clientID
      • FROM clients
      • WHERE name="Georgeanna" OR name="Wanda");

      Output

      Query OK, 4 rows affected, 1 warning (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 1

      Notice that this example uses a subquery in the WHERE clause to return Georgeanna and Wanda’s clientID values from the clients table. Oftentimes, abstract values like identification numbers can be hard to remember, but this method of using a subquery to find a value can be helpful when you only know certain attributes about the records in question.

      After updating the shows table, query it once again to confirm that the changes went through as expected:

      Output

      +--------+------------+----------+------------+-------------+ | showID | showDate | clientID | attendance | ticketPrice | +--------+------------+----------+------------+-------------+ | 1 | 2019-12-25 | 4 | 144 | 22.50 | | 2 | 2020-01-11 | 5 | 84 | 29.50 | | 3 | 2020-01-17 | 3 | 190 | 19.49 | | 4 | 2020-01-31 | 5 | 234 | 14.99 | | 5 | 2020-02-08 | 1 | 86 | 25.00 | | 6 | 2020-02-14 | 3 | 122 | 59.25 | | 7 | 2020-02-15 | 2 | 101 | 26.50 | | 8 | 2020-02-27 | 2 | 186 | 19.99 | | 9 | 2020-03-06 | 4 | 222 | 45.00 | | 10 | 2020-03-07 | 5 | 250 | 8.99 | +--------+------------+----------+------------+-------------+ 10 rows in set (0.00 sec)

      Once again, this output indicates that the UPDATE statement completed successfully.

      Using JOIN Clauses to Update Data in Multiple Tables

      Up to this point, this guide has only shown how to update data in one table at a time. However, some SQL implementations allow you to update multiple columns in multiple tables by temporarily combining the tables with a JOIN clause.

      Here’s the general syntax you can use to update multiple tables with a JOIN clause:

      • UPDATE table_1 JOIN table_2
      • ON table_1.related_column = table_2.related_column
      • SET table_1.column_name = value_expression,
      • table_2.column_name = value_expression
      • WHERE conditions_apply;

      This example syntax begins with the UPDATE keyword followed by the names of two tables, separated by a JOIN clause. Following that is the ON clause, which describes how the query should join the two tables together.

      In most implementations, you can join tables by finding matches between any set of columns that have what the SQL standard refers to as “JOIN eligible” data types. This means that, in general, you can join any column holding numeric data with any other column that holds numeric data, regardless of their respective data types. Likewise, you can join any columns that hold character values with any other column holding character data.

      Note that because JOIN clauses compare the contents of more than one table, this example syntax specifies which table to select each column from by preceding the name of the column with the name of the table and a period. This is known as a fully qualified column reference. You can specify which table a column should be selected from like this for any operation, although it’s typically only used to improve clarity when working with multiple tables.

      To illustrate with the sample tables created previously, run the following UPDATE statement. This will join the clients and shows tables on their respective clientID columns, and then update the routine and ticketPrice values for Gladys’s record in the clients table and each of her performances listed in the shows table:

      • UPDATE clients JOIN shows
      • USING (clientID)
      • SET clients.routine="mime",
      • shows.ticketPrice = 30
      • WHERE name="Gladys";

      Output

      Query OK, 2 rows affected (0.01 sec) Rows matched: 2 Changed: 2 Warnings: 0

      Notice that this example joins the tables with the USING keyword instead of the ON keyword used in the previous example syntax. This is possible because both tables have a clientID column that share a similar data type.

      For a more in-depth tutorial on JOIN operations, see our guide on How To Use Joins in SQL.

      Changing Foreign Key UPDATE Behavior

      By default, any UPDATE statement that would cause a conflict with a FOREIGN KEY constraint will fail.

      Recall from the Connecting to MySQL and Setting up a Sample Database section of the Prerequisites that the clientID column of the shows table is a foreign key that references the clientID column of the clients table. This means that any value entered into the shows table’s clientID column must already exist in that of the clients table.

      If you attempt to update the clientID value of a record in the clients table that also appears in the clientID column of the shows table, it will cause an error:

      • UPDATE clients
      • SET clientID = 9
      • WHERE name="Ann";

      Output

      ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

      You can avoid this error by replacing the existing foreign key constraint with one that treats UPDATE operations differently.

      Note: Not every relational database management system or engine allows you to add or remove a constraint from an existing table as outlined in the following paragraphs. If you’re using an RDBMS other than MySQL, you should consult its official documentation to understand what limitations it has for managing constraints.

      To replace the current constraint, you must first remove it with an ALTER TABLE statement. Recall that in the CREATE TABLE statement for shows, we defined client_fk as the name for the table’s FOREIGN KEY constraint:

      • ALTER TABLE shows
      • DROP FOREIGN KEY client_fk;

      Output

      Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0

      Following that, create a new foreign key constraint that’s configured to treat UPDATE operations in a way that makes sense for the given use case. Aside from the default setting which prohibits UPDATE statements that violate the foreign key, there are two other options available on most RDBMSs:

      • ON UPDATE SET NULL: This option will allow you to update records from the parent table, and will reset any values in the child table that reference them as NULL.
      • ON UPDATE CASCADE: When you update a row in the parent table, this option will cause SQL to automatically update any records that reference it in the child table so that they align with the new value in the parent table.

      For the purposes of this example, ON UPDATE SET NULL doesn’t make sense. After all, if you change one of your clients’ identification numbers but don’t remove them from the clients table, they should still be associated with their performances in the shows table. Their new identification number should be reflected in their performances’ records, so the ON UPDATE CASCADE option makes more sense for our purposes.

      To add a FOREIGN KEY constraint that follows the ON UPDATE CASCADE behavior, run the following ALTER TABLE statement. This creates a new constraint named new_client_fk which replicates the previous constraint definition, but includes the ON UPDATE CASCADE option:

      • ALTER TABLE shows
      • ADD CONSTRAINT new_client_fk
      • FOREIGN KEY (clientID)
      • REFERENCES clients (clientID)
      • ON UPDATE CASCADE;

      Output

      Query OK, 10 rows affected (0.02 sec) Records: 10 Duplicates: 0 Warnings: 0

      This output tells you that the operation impacted all ten rows in the shows table.

      Note: Instead of altering a table’s definition to change how a foreign key handles UPDATE operations, you can define this behavior from the start in the CREATE TABLE statement like this:

      • CREATE TABLE shows
      • (showID int PRIMARY KEY,
      • showDate date,
      • clientID int,
      • attendance int,
      • ticketPrice decimal (4,2),
      • CONSTRAINT client_fk
      • FOREIGN KEY (clientID)
      • REFERENCES clients(clientID)
      • ON UPDATE CASCADE
      • );

      Following that, you’ll be able to update the clientID value of any record in the clients table, and those changes will cascade down to any rows in the shows table that reference it:

      • UPDATE clients
      • SET clientID = 9
      • WHERE name="Ann";

      Output

      Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0

      Although this output says it only affected one row, it will have also updated the clientID value of any performance records in the shows table associated with Ann. To confirm this, run the following query to retrieve all the data from the shows table:

      Output

      +--------+------------+----------+------------+-------------+ | showID | showDate | clientID | attendance | ticketPrice | +--------+------------+----------+------------+-------------+ | 1 | 2019-12-25 | 4 | 144 | 22.50 | | 2 | 2020-01-11 | 9 | 84 | 29.50 | | 3 | 2020-01-17 | 3 | 190 | 19.49 | | 4 | 2020-01-31 | 9 | 234 | 14.99 | | 5 | 2020-02-08 | 1 | 86 | 30.00 | | 6 | 2020-02-14 | 3 | 122 | 59.25 | | 7 | 2020-02-15 | 2 | 101 | 26.50 | | 8 | 2020-02-27 | 2 | 186 | 19.99 | | 9 | 2020-03-06 | 4 | 222 | 45.00 | | 10 | 2020-03-07 | 9 | 250 | 8.99 | +--------+------------+----------+------------+-------------+ 10 rows in set (0.00 sec)

      As expected, the update made to the clientID column in the clients table cascaded down to the associated rows in the shows table.

      Conclusion

      By reading this guide, you learned how to change existing records in or more tables using SQL’s UPDATE statement. You also learned how SQL handles UPDATE operations that conflict with foreign key constraints, and how to change that default behavior.

      The commands outlined here should work on any database management system that uses SQL. Keep in mind that every SQL database uses its own unique implementation of the language, so you should consult your DBMS’s official documentation for a more complete description of how it handles UPDATE operations and what options are available for them.

      If you’d like to learn more about working with SQL, we encourage you to check out the other tutorials in this series on How To Use SQL.



      Source link

      11 Things Website Owners Should Update During a Crisis


      Ever since the coronavirus crisis hit, it can sometimes feel like it has affected every area of our lives. Anyone who is now homeschooling kids or suddenly spending way too much time over a hot stove can vouch for that! Of course, that includes business too, and if you’re a business owner, there’s a good chance you’ve really felt that impact.

      “In my 13 years as a marketing agency owner, I never dreamed of this time, when my team and I are assisting hundreds of struggling small businesses to understand how best to market and communicate now to save their businesses,” says Wendy O’Donovan Phillips, CEO of Big Buzz.

      “Re-evaluate your vision statement to focus the team’s efforts through this time,” she advises. “Revisit your SWOT (strengths, weaknesses, opportunities, threats) analysis with a particular focus on opportunities. Your clients and community have different needs now than they did even a month ago and will have different needs in another month. This approach will help you more readily hit your revenue and profit projections. Take the right action, and you will survive!”

      It’s time to create a crisis management plan. One of the most crucial things you’ll need to tackle as a small business owner is updating your website and social media channels.

      To keep your small business on the up and up, we’ve identified 11 things website owners should update during a crisis. Let’s dive in.

      How to Update Your Website During a Crisis

      1. Create a new landing page.

      When people visit your website, your homepage is likely the first thing they’ll see. That’s why keeping it fresh is always crucial, but with things in flux during a crisis, that’s even more important.

      To show that your business is on the ball and staying up to date, you’ll want to create a landing page for crisis-related content. Make sure to change the page often, especially when new information is released or policies evolve. If those affect your business, outline how you’ll be implementing anything new and how that will impact customers. Every time you update it, you can spread the word on social media by sharing a link.

      Another reason to continue refreshing your landing page is that search engines will recognize it’s a key page on your site for the crisis, which will boost SEO.

      2. Update your FAQ page.

      If you don’t have a FAQ section on your business website yet, it’s time to add one! The COVID-19 crisis is changing every day, so a FAQ section is a great place to address that and share your updates. Local businesses especially need to answer common questions about their crisis management and how your company is adapting because of restrictions due to COVID-19.

      To ensure that clients are aware of your FAQ section, you can spotlight a link to it on your homepage. Continue to add relevant information to your FAQ page, such as how you’re keeping employees safe, who comes into contact with your products, and policy changes, for instance.

      The FAQ section is also an opportunity to share any changes in your supply chain, offerings or any potential product fulfillment delays.

      “Always ensure you have the right resources to deploy readily available,” says Bob Minhas, Founder and Lead Trainer for eSchool for Entrepreneurs. “Whether documents or videos, walk through your customer journey and understand what they might need to know to complete a transaction with you online and have the right FAQ ready for them.”

      3. Change your menu/navigation.

      To make it easy to find your crisis content, it’s a good idea to add a link in your main navigation or an alert bar that sits above the navigation to your crisis landing page. Be sure to keep the title of the new navigation item short.

      Plus, regardless of the status of a crisis situation, it’s always a good idea to update your navigation to keep it timely and relevant, which should be part of a best practices strategy for your website.

      4. Review your product descriptions.

      Have your offerings changed in any way since the crisis started? Then you’ll want your website to reflect that. Change the text accordingly and add item availability information to postings.

      “A lot of small businesses that we work with are looking to add new services or products that are complimentary and interesting to the audiences they have built both online and in previous customers,” says Chris Sica, Chief Revenue Officer, The Ronin Society. “We encourage business owners to step into their customers’ shoes, think about the new buying journeys they are going to be on, what new pain points they will be experiencing and attempt to solve those using the resources they already have available to them.”

      5. Check your events page.

      If your business hosts events of any kind, you’ll want to give updates on how the schedule has changed, including if they’ve been cancelled, postponed or are going virtual.

      To avoid confusion, continue to list the original event date so that clients can confirm the event. For events that have been changed from in-person to digital, be sure to link to the virtual location for easy access.

      6. Make a homepage hero.

      In the midst of a crisis, everyone could use some good news. If you’ve realigned your business to help in any way, make it easy for customers to find out by updating your homepage. For example, if you’re now doing carryout or delivery, be sure to spread the word.

      “A delivery option is absolutely essential now,” Sica says. “Lots of customers still want to get out of the house and curbside pickup gives them a bit of a break from being at home. [Another element to expand is] payment options to make it easy to afford your product or service.”

      7. Utilize pop-ups or banners.

      One of the easiest ways to catch your clients’ attention and update them is to add a pop-up or banner. It’s an easy way to spread the word about reduced hours, limited inventory, shipping delays or changes in service availability. Make sure that it visually grabs people’s attention.

      8. Refresh local listings.

      If your hours have changed, the world needs to know. Be sure to update your website. Additionally, you’ll need to adjust hours and temporary closures on platforms where customers go to find your hours, such as Google My Business, Facebook and Yelp.

      9. Update your scheduled messaging.

      If you regularly send out pre-scheduled emails or social media updates, be sure to adjust them to fit the current situation. Otherwise, if you send out the same old communication, it can make you appear tone-deaf and not up to speed.

      “Customers are used to coming by your shop, seeing your advertisements, or whatever your traction channel is,” Sica says. “Their entire user experience with your brand has been removed or changed. Their fears and pain points have been altered. As a result, you need to make sure that you stay top of mind in a useful way. The easiest solution is by creating or updating your newsletters. We’ve also seen businesses create how-to videos for clients based on in-store or online products they like, and we’ve also seen customer happy hours.”

      10. Change your social media accounts.

      At the minimum, ensure that your business hours, closures, and product availability information remains updated for the duration of the coronavirus outbreak.

      Just to be on the safe side, it’s best to post more than once on your regular social media channels about any business changes, since we all know how quickly a Tweet can disappear to the bottom of a Twitter feed. This increases the odds that customers will see the news.

      11. Increase crisis communication.

      Ensure everyone is up to speed by sending updates via email, texts or blog posts — communicate with your customers in the way that is best for them.

      “It is important to stay in touch with customers,” says Jaryd P. Kase, Principal at Kase Consulting, LLC. “First off, if you are open, your customers might not know and they should know you are open. Second, your customers are dealing with the same crisis as you. By communicating how you are working to mitigate risk factors in the pandemic or working hard to continue bringing them a great product or service (or pick up where you left off if you are closed), it helps put the customer at ease that their favorite store or an important supplier isn’t going out of business.”

      However, there is a fine line between communicating too much and too little. “Communication with customers should be tempered,” says Deborah S. Sweeney, CEO of MyCorporation.com. “It is important to not over-communicate or be too sales-y. Share information cautiously. Share content and information, but don’t try to sell. Inform and educate.”

      Looking for Remote Work Tips?

      Whether you want to stay focused at home or increase team engagement, we can help! Subscribe to the DreamHost Digest so you never miss an article.

      Your Crisis Management Team

      The coronavirus pandemic — and the resulting economic downturn —  is making things tough for small business owners. At DreamHost, we’ve provided digital homes for small businesses for more than two decades. In that time, we’ve learned that entrepreneurs are scrappy, smart, and savvy. We believe in you and your business and are here to help.



      Source link

      How to Update Drupal 8 on CentOS 8


      Updated by Linode

      Written by Linode

      Drupal 8 is the latest version of the popular Drupal content management system. While Drupal 8.1 includes a simple feature for incremental updates, you must preform manual Drupal core updates for any preceding versions. This guide demonstrates how to manually install an incremental Drupal 8 update on your Linode. The examples in this guide assume you have a functional Drupal 8 installation running a LAMP stack on CentOS 8.

      Before You Begin

      1. Complete all the steps in the Install and Configure Drupal 8 on CentOS 8 guide.

      2. If you followed the Install and Configure Drupal 8 on CentOS 8 guide, your site’s document root should be in the /var/www/html/example.com/ directory, where example.com is your own site’s domain name. You can list all your directories in /var/www/html to verify the location of your site’s document root.

        ls /var/wwww/html/
        
      3. Update your CentOS 8 system if you did not complete that step while installing Drupal 8.

        sudo yum update
        

        Note

        This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, visit our Users and Groups guide.

        All configuration files should be edited with elevated privileges. Remember to include sudo before running your text editor.

      Create Backups

      In this section, you will create an archive of your Drupal site’s files and store the archive in a backups directory. If needed, you could extract the compressed files in your backup archive to restore the state of your site prior to updating it.

      1. Create a backups directory in your site’s document root to store any backups you make of your Drupal site.

        sudo mkdir /var/www/html/example.com/backups
        
      2. Create an archive of your existing site files and move it into the backups directory. Ensure you replace example.com with your own site’s domain name.

        cd /var/www/html/example.com/public_html
        sudo tar -cvzf example.com-BCKP-$(date +%Y%m%d).tar.gz ./
        sudo mv -v example.com-BCKP-*.tar.gz ../backups
        

        Note

        This process can also be scripted and run on a regular basis using cron.

      Download Updates

      You are now ready to check your Drupal system for available updates. Once you have identified the necessary updates, you will download them as an archive to your Linode.

      1. Log in to your Drupal site and navigate to the Admin Toolbar. Click on Reports and then on Available updates.

        Note

        If Available updates is not listed, enable the Update Manager module by navigating to the Extend menu item in the Admin Toolbar. See Drupal’s documentation for more details on enabling modules.
      2. Right click the link under the RECOMMENDED VERSION heading and copy the link address and paste it somewhere you can access later.

        A Drupal Update

        Note

        If you receive an error when your Drupal 8 installation checks for available updates, it may be having issues communicating with the Drupal website to see if there are updates. You can check your site’s recent log messages, by navigating to Reports and selecting Recent log messages to further investigate the issue.

        If your CentOS installation is running in enforcing mode, ensure you are allowing httpd to make network connections. One way to do this is to set the corresponding SELinux boolean to true:

        sudo setsebool httpd_can_network_connect true
        

        Also, ensure that firewalld is allowing https traffic:

        sudo firewall-cmd --zone=public --add-service=https
        
      3. Connect to your Linode over SSH:

        ssh [email protected]
        
      4. Navigate to your site’s directory. Download the Drupal core archive using wget and pasting the link address you copied from Step 2. Ensure you replace example.com with your own site’s directory name.

        cd /var/www/html/example.com
        sudo wget https://ftp.drupal.org/files/projects/drupal-8.8.2.tar.gz
        

      Upgrade Your Site

      Now that the Drupal core archive is saved to your Linode, you are ready to proceed with the version upgrade of your site.

      Enable Maintenance Mode

      Drupal’s maintenance mode allows users with the right permissions to use your site while everyone else will be presented with a message that the site is under maintenance.

      1. While logged into your Drupal site, navigate to Configuration. Under the Development heading, click on Maintenance mode.

        Maintenance Mode

      2. Check the box next to “Put site into maintenance mode.” Enter a message if desired, and click Save Configuration.

        Turn on Maintenance Mode

      Replace System Files

      1. Toggle back to your terminal window and ensure you are connected to your Linode over SSH.

        ssh [email protected]
        
      2. Navigate to your site’s /var/www/html/example.com/public_html directory and remove existing files and folders except sites and profiles. Ensure you replace example.com with your own site’s directory name.

        cd /var/www/html/example.com/public_html
        sudo rm -ifr autoload.php composer.* example.gitignore index.php LICENSE.txt README.txt robots.txt update.php web.config && sudo rm -ifr core/ modules/ vendor/ themes/
        
      3. Go up one directory to /var/www/html/example.com/ and expand the Drupal core archive that you downloaded in the Download Updates section into your public_html folder. Replace drupal-8.8.2.tar.gz with the name of the archive you downloaded:

        cd ..
        sudo tar -zxvf drupal-8.8.2.tar.gz --strip-components=1 -C public_html
        
      4. From a browser on your local machine, navigate to the following URL on your Drupal site www.example.com/update.php. Ensure you replace example.com with your own site’s domain name. Follow the prompts to continue the update.

        Note

        If update.php does not load or returns a 403 Forbidden error, you may need to update the ownership and permissions of the newly expanded files. For best practices on Drupal site directory and file permissions, see their documentation.
      5. If you are installing additional modules or configuring additional security settings, complete those updates now and continue on to the next step in this section when you are done.

        Note

        The Next Steps section includes a list of Drupal security modules you may consider installing.
      6. Rebuild the site’s cache by navigating to the Admin Toolbar and click on Configuration. Under the Development heading, click on Performance. Finally, click on the Clear all caches button.

      7. Verify your site’s status by viewing its status report. In the Admin Toolbar, click on Reports, then click on Status report.

      8. If the update was successful and your status report does not display any unexpected information, take the site out of maintenance mode by following step 2 in the Enable Maintenance Mode section. Ensure you uncheck the box next to the “Put site into maintenance mode” setting.

      Next Steps

      As a next step, consider installing additional security modules from the Drupal Project Module:

      This guide is published under a CC BY-ND 4.0 license.



      Source link