{"id":4506,"date":"2013-02-06T16:55:31","date_gmt":"2013-02-06T16:55:31","guid":{"rendered":"http:\/\/craftydba.com\/?p=4506"},"modified":"2013-02-06T19:15:53","modified_gmt":"2013-02-06T19:15:53","slug":"column-design-with-ssms","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=4506","title":{"rendered":"Column Design with SSMS"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/column_icon.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/column_icon.jpg\" alt=\"\" title=\"column_icon\" width=\"128\" height=\"128\" class=\"alignleft size-full wp-image-4542\" \/><\/a>Most of the articles that I presented so far for database development have been centered around the exact Microsoft T-SQL syntax to perform a certain operation.  At the <a href=\"http:\/\/www.cs.uri.edu\/\">University of Rhode Island<\/a>, I learnt how to program in Pascal before typing in my first ANSI SQL statement.  In short, I will always be some type of developer in my heart.  <\/p>\n<p>However, many people do not come from a computer science and math background.  The SQL Server Management Studio (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb934498.aspx\">SSMS<\/a>) has menus and dialog boxes to achieve many of the same results.  <\/p>\n<p>Today, I am going to continue the series of articles that will recreate the [AUTOS] sample database while demonstrating how common T-SQL tasks in my <a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/designing-with-ssms.sql_.txt\">script<\/a> can be done with SSMS.  I want to explore how to ADD, ALTER and DELETE columns using the SSMS graphical interface.  Please see section 1I in the code for the table and column definitions.<\/p>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190273.aspx\">ALTER TABLE<\/a> &#8211; &#8220;Modifies a table definition by altering, adding, or dropping columns and constraints, reassigning partitions, or disabling or enabling constraints and triggers&#8221; &#8211; MSDN quote.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/makes-table-definition.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/makes-table-definition.jpg\" alt=\"\" title=\"makes-table-definition\" width=\"246\" height=\"155\" class=\"alignleft size-full wp-image-4515\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We will be focusing on making the [DBO].[MAKES] table look like our data model.  Right click the [AUTOS] database and choose New Table.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Add [MAKER_ID] as the first surrogate key field and the [MAKER_NM] as second natural key field and the two year fields ([START_YR] &#038; [END_YR]) as regular integers [INT].  <\/p>\n<p>I will be glossing over these steps since they were first introduce when I <a href=\"https:\/\/craftydba.com\/?p=4418\">talked<\/a> about Table Design with SSMS.  In short, SSMS is executing a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190273.aspx\">ALTER TABLE ADD COLUMN<\/a> command in the background.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-11.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-11-300x300.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ADD-COLUMN-STEP-1\" width=\"300\" height=\"300\" class=\"alignleft size-medium wp-image-4512\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-11-300x300.jpg 300w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-11-150x150.jpg 150w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-11.jpg 825w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-2-264x300.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ADD-COLUMN-STEP-2\" width=\"264\" height=\"300\" class=\"alignright size-medium wp-image-4508\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-2-264x300.jpg 264w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-2.jpg 729w\" sizes=\"auto, (max-width: 264px) 100vw, 264px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-3-300x298.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ADD-COLUMN-STEP-3\" width=\"300\" height=\"298\" class=\"aligncenter size-medium wp-image-4509\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-3-300x298.jpg 300w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-3-150x150.jpg 150w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-COLUMN-STEP-3.jpg 832w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Please note that we could have defined default constraints or values within the table designer.  If we had a computed column, we could have defined it within the column properties.  However, there is no expression builder to make this action easier than coding on the fly.<\/p>\n<p>After recreating both tables and constraints, we find out that the business line wants the [MAKER_ID] to be stored as big integer [BIGINT].  <\/p>\n<p>How can we make this happen?<\/p>\n<p>Find the [MAKER_ID] column in the object explorer under the table name.  Right click and select the modify column menu option.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ALT-COLUMN-STEP-1\" width=\"418\" height=\"429\" class=\"aligncenter size-full wp-image-4521\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-1.jpg 418w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-1-292x300.jpg 292w\" sizes=\"auto, (max-width: 418px) 100vw, 418px\" \/><\/a><\/p>\n<p>Find the [MAKER_ID] column in the table designer and change the data type to [BIGINT].  A warning message box will come up stating that [MAKER_ID] is part of a foreign key relationship and will need to be change in the parent table.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ALT-COLUMN-STEP-2\" width=\"541\" height=\"626\" class=\"aligncenter size-full wp-image-4529\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-2.jpg 541w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-2-259x300.jpg 259w\" sizes=\"auto, (max-width: 541px) 100vw, 541px\" \/><\/a><\/p>\n<p>Click the save toolbar button to commit the change.  A error message box will show up stating that the change could note be made due to the fact that the tables contain data and participate in a relationship.  <\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-3.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ALT-COLUMN-STEP-3\" width=\"539\" height=\"621\" class=\"aligncenter size-full wp-image-4531\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-3.jpg 539w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ALT-COLUMN-STEP-3-260x300.jpg 260w\" sizes=\"auto, (max-width: 539px) 100vw, 539px\" \/><\/a><\/p>\n<p>I have always had issues when there are dependent objects defined on a table column that I want to modify.  Therefore, it is very important to get a table design correct the first time.  Another solution is to create a duplicate table under a different schema and move the data from one schema to another.  Then, break all the relationships, delete the original table, move the table to the old schema and recreate the relationships.  As you can see, this is a-lot of work.  <\/p>\n<p>In a nutshell, SSMS is trying to execute a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190273.aspx\">ALTER TABLE ALTER COLUMN<\/a> command in the background.<\/p>\n<p>Let&#8217;s try deleting the [END_YR] column from the [MAKES] table.  Again, find the column under the table node in the object explorer.  Right click and select the delete action from the menu.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-COLUMN-STEP-1\" width=\"418\" height=\"415\" class=\"aligncenter size-full wp-image-4532\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-1.jpg 418w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-1-150x150.jpg 150w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-1-300x297.jpg 300w\" sizes=\"auto, (max-width: 418px) 100vw, 418px\" \/><\/a><\/p>\n<p>The delete object dialog box comes up showing that you want to remove the column.  Click OKAY to continue the action and CANCEL to abort.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-COLUMN-STEP-2\" width=\"704\" height=\"630\" class=\"aligncenter size-full wp-image-4533\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-2.jpg 704w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-2-300x268.jpg 300w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/a><\/p>\n<p>A error message stating that a CHECK CONSTRAINT is defined on the column.  Therefore, the column can not be dropped.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-3.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-COLUMN-STEP-3\" width=\"832\" height=\"632\" class=\"aligncenter size-full wp-image-4535\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-3.jpg 832w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-3-300x227.jpg 300w\" sizes=\"auto, (max-width: 832px) 100vw, 832px\" \/><\/a><\/p>\n<p>Find the constraint named CHK_END_YR in the object explorer.  This will be located under the [DBO].[MAKES] table.  Right click and select the delete action from the menu.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-6.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-6.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-COLUMN-STEP-6\" width=\"464\" height=\"470\" class=\"aligncenter  size-full wp-image-4557\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-6.jpg 464w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-6-296x300.jpg 296w\" sizes=\"auto, (max-width: 464px) 100vw, 464px\" \/><\/a><\/p>\n<p>The delete object dialog box comes up showing that you want to remove the column.  Click OKAY to continue the action.  This action will complete successfully.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-4.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-COLUMN-STEP-4\" width=\"703\" height=\"631\" class=\"aligncenter size-full wp-image-4534\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-4.jpg 703w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-4-300x269.jpg 300w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/a><\/p>\n<p>Repeat the process to delete the [END_YR] column.  Confirm the delete action in the dialog box.  This action will complete successfully.  Another look at the [DBO].[MAKES] table shows the column not longer exists.  To recap, SSMS is trying to executing a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190273.aspx\">ALTER TABLE DROP COLUMN<\/a> command in the background.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-5.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-5.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-COLUMN-STEP-5\" width=\"400\" height=\"181\" class=\"aligncenter size-full wp-image-4536\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-5.jpg 400w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-COLUMN-STEP-5-300x135.jpg 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>In summary, we can perform many of the Data Definition Language (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Data_definition_language\">DDL<\/a>) tasks with the SQL Server Management Studio (SSMS) graphical interface. I just went over the ADD COLUMN, ALTER COLUMN, and DROP COLUMN clauses of the ALTER TABLE statement.  These actions were done using SSMS.  It is important to note that object dependencies can cause you trouble when altering or deleting columns.<\/p>\n<p>Next time, I will be talking about Crafting Constraints with SSMS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the articles that I presented so far for database development have been centered around the exact Microsoft T-SQL syntax to perform a certain operation. At the University of Rhode Island, I learnt how to program in Pascal before typing in my first ANSI SQL statement. In short, I will always be some type of developer in my heart. However, many people do not come from a computer science and math background. The SQL Server Management Studio (SSMS) has menus and dialog boxes to achieve many of the same&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[684,686,64,764,31,685,12,15,28,741,470,763],"class_list":["post-4506","post","type-post","status-publish","format-standard","hentry","category-db-dev","tag-add-column","tag-alter-column","tag-alter-table","tag-column-dependencies","tag-database-developer","tag-drop-column","tag-free-code","tag-john-f-miner-iii","tag-sql-server","tag-sql-server-management-studio","tag-ssms","tag-table-dependencies"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/4506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4506"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/4506\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}