풀리퀘스트를 병합하는 경우 Jira Automation 규칙

Posted by: AJ Welch

Changing the data structure of a column in SQL Server from NULL to NOT NULL, thereby disallowing non-null values in that column, is generally performed using the relatively simple ALTER TABLE syntax to appropriately change the column in question.

In this tutorial we’ll examine the important safety precautions necessary when altering existing data in a column, prior to actually issuing any ALTER commands that would potentially cause harm to the table itself.

애자일 너머를 향해

Before any changes are made to your table, it’s important to briefly go over what data can (and cannot) be specified within an existing column that you wish to alter to NOT NULL, ensuring that no row is allowed to have a NULL value in that column.

Most critically, all existing NULL values within the column must be updated to a non-null value before the ALTER command can be successfully used and the column made NOT NULL. Any attempt to set the column to NOT NULL while actual NULL data remains in the column will result in an error and no change will occur.

Unnullifying existing column data

To ensure that there are no NULL values in our column, we’ll use a basic UPDATE command, applicable explicitly to rows where the value is currently NULL. For example, we have a basic table of client data with nameemail, and phone. Currently a few of the records have a NULL phone value, which we don’t want to allow:

clientsID     name              email                                         phone
1             Neville Estes                         1-843-863-2697
2             Flynn Fry
3             Wyatt Schmidt                          1-950-895-1847
4             Oleg Hill        1-173-344-1578
5             Randall Bullock
6             Lamar White                              1-421-757-4907
7             Fuller Hill                        1-178-437-8281
8             Ulysses Boyle   1-535-515-1494
9             Paki Palmer
10            Kamal Buchanan           1-325-847-4838

Therefore, we can insert a default value for all the phone values that are currently NULL with the following statement:

  phone = '0-000-000-0000'
  phone IS NULL;

Now our NULL values have all been replaced with the value we consider the default0-000-000-0000:

clientsID   name            email                                       phone
1           Neville Estes                       1-843-863-2697
2           Flynn Fry                          0-000-000-0000
3           Wyatt Schmidt                        1-950-895-1847
4           Oleg Hill      1-173-344-1578
5           Randall Bullock                                0-000-000-0000
6           Lamar White                            1-421-757-4907
7           Fuller Hill                      1-178-437-8281
8           Ulysses Boyle 1-535-515-1494
9           Paki Palmer                             0-000-000-0000
10          Kamal Buchanan         1-325-847-4838

애자일 너머를 향해

Now that there are no NULL values any longer, we can issue our ALTER statement to update the column so all future additions do not allow NULL values. Since we’re altering the phone column in this example, the statement will look something like this:


Verify altered nullability

Once the alteration to your column is made, it is a good practice to verify the column no longer allows any NULL values by running a simple INSERT test and trying to insert a new record with the NULL value in the altered column:

  clients(name, email, phone)
  ('John Doe', '', NULL);

If all went according to plan, SQL Server will issue an error stating that the column doesn’t allow NULL values:

Cannot insert the value NULL into column 'phone', table 'library.dbo.clients'; column does not allow nulls. INSERT fails. [SQL State=23000, DB Errorcode=515]

다음 주제