{"id":4418,"date":"2013-02-05T02:07:19","date_gmt":"2013-02-05T02:07:19","guid":{"rendered":"http:\/\/craftydba.com\/?p=4418"},"modified":"2017-10-08T16:39:57","modified_gmt":"2017-10-08T16:39:57","slug":"table-design-with-ssms","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=4418","title":{"rendered":"Table Design with SSMS"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/table_icon_2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/table_icon_2.jpg\" alt=\"\" title=\"table_icon_2\" width=\"128\" height=\"128\" class=\"alignleft size-full wp-image-4420\" \/><\/a><\/p>\n<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 <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 will be going over section 1I in the sample code with a little literary lead way to go off topic when necessary to demonstrate my ideas.<\/p>\n<p>I want to explore how the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms174979.aspx\">CREATE TABLE<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190273.aspx\">ALTER TABLE<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms173790.aspx\">DROP TABLE<\/a> statements can be executed within the SSMS graphical interface.<\/p>\n<p>When ever I write code to be executed in a batch script, I always determine if an object exists before creating it.  My code seldom breaks since I delete the object if it exists.  <\/p>\n<p>The screen shot below shows an existing [ACTIVE].[MAKES] table in the [AUTOS] database.  To delete the table (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms173790.aspx\">DROP TABLE<\/a>), select it in the object explorer and right click.  Choose the delete sub-menu option.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-TABLE-STEP-1\" width=\"422\" height=\"641\" class=\"aligncenter size-full wp-image-4427\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-1.jpg 422w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-1-197x300.jpg 197w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/a><\/p>\n<p>This action will bring up the delete object dialog box.  It shows the name, type and owner of the object.  Double check these values before clicking OKAY to remove the table or click CANCEL to abort the action.  For this article, please remove the table since we are going to rebuild it over a series of talks.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-DEL-TABLE-STEP-2\" width=\"706\" height=\"632\" class=\"aligncenter size-full wp-image-4430\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-2.jpg 706w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-DEL-TABLE-STEP-2-300x268.jpg 300w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/a><\/p>\n<p>To create a new table, select the Tables parent node in the object explorer and right click to bring up the sub-menu.  Choose the New Table option.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ADD-TABLE-STEP-1\" width=\"510\" height=\"446\" class=\"aligncenter size-full wp-image-4433\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-1.jpg 510w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-1-300x262.jpg 300w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/a><\/p>\n<p>Every table must have at least one column defined.  The table designer allows a developer or administrator to enter in the column name, data type, and all the various options that you can choose.  <\/p>\n<p>For our example, we are just going to add the [MAKERS_ID] column to the table as a not null integer.  Find the identity specification in the column properties list and change it to yes.  It will default to a seed value of 1 and a increment value of 1.<\/p>\n<p>Now that we have a column defined, do you think we can just click save?  The answer is no since we want the table to be under the [ACTIVE] security schema and storage to be allocated from the<br \/>\n[FG_AUTOS_ACTIVE] file group.<\/p>\n<p>We need to bring up the properties window of the table to make these selections.  Hitting the F4 key will bring up this floating window.  Change the Schema and Regular Data Space Specification to the values we want.<\/p>\n<p>The quickest way to save changes to both the table properties and table designer is to click the SAVE ALL button on the tool bar.  This action will create (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms174979.aspx\">CREATE TABLE<\/a>) the new simple table that we can build upon.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-ADD-TABLE-STEP-2\" width=\"1170\" height=\"824\" class=\"aligncenter size-full wp-image-4436\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-2.jpg 1170w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-2-300x211.jpg 300w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-ADD-TABLE-STEP-2-1024x721.jpg 1024w\" sizes=\"auto, (max-width: 1170px) 100vw, 1170px\" \/><\/a><\/p>\n<p>Table and Indexes are two commonly used objects in a database.  Choosing the correct properties of each can lead to either a successful or disastrous design.<\/p>\n<p>Let&#8217;s select the new table in the object explorer, right click and select properties.  You will notice a dialog box will five different pages is shown.<\/p>\n<p>The first page shows the <span style=\"color: #FF0000;\">general properties<\/span> of the table.  This includes schema name, table name, creation date, and system table flag to name a few.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-1.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-SHOW-TABLE-STEP-1\" width=\"736\" height=\"632\" class=\"aligncenter size-full wp-image-4443\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-1.jpg 736w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-1-300x257.jpg 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/a><\/p>\n<p>The second page shows the <span style=\"color: #FF0000;\">user or role permissions<\/span> given on the table.  This is empty right now since we did not give out rights at the table level.  We will explore administering rights with SSMS next time.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-2.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-SHOW-TABLE-STEP-2\" width=\"735\" height=\"631\" class=\"aligncenter size-full wp-image-4444\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-2.jpg 735w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-2-300x257.jpg 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/a><\/p>\n<p>The third page shows the <span style=\"color: #FF0000;\">change tracking properties<\/span> of the table.  Again, this is empty since we did not enable change tracking on the table in the [AUTOS] database.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-3.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-SHOW-TABLE-STEP-3\" width=\"735\" height=\"631\" class=\"aligncenter size-full wp-image-4448\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-3.jpg 735w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-3-300x257.jpg 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/a><\/p>\n<p>The fourth page shows the <span style=\"color: #FF0000;\">storage properties<\/span> of the table.  Please note the file group that the table is stored on.  <\/p>\n<p>Some other cool things shown in the window are the data and index space used as well as the total number of records.  Why execute a <span style=\"color: #008000;\">SELECT COUNT(*) FROM [ACTIVE].[MAKES]<\/SPAN> query when the information we want is a right click away, or at least in a system table?  <\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-4.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-SHOW-TABLE-STEP-4\" width=\"736\" height=\"632\" class=\"aligncenter size-full wp-image-4450\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-4.jpg 736w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-4-300x257.jpg 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/a><\/p>\n<p>The fifth page shows the <span style=\"color: #FF0000;\">extended properties<\/span> of the table.  This is where used defined properties associated with the table can be declared.   <\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-5.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-5.jpg\" alt=\"\" title=\"SSMS-AUTOS-DB-SHOW-TABLE-STEP-5\" width=\"735\" height=\"632\" class=\"aligncenter size-full wp-image-4451\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-5.jpg 735w, https:\/\/craftydba.com\/wp-content\/uploads\/2013\/02\/SSMS-AUTOS-DB-SHOW-TABLE-STEP-5-300x257.jpg 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/a><\/p>\n<p>If we script out the Microsoft Transaction SQL for the action to add a comment to the table, we get the following command.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"microsoft sql server - comments\">\r\n-- Microsoft T-SQL Syntax\r\nEXEC sys.sp_addextendedproperty \r\n    @name=N'Description', \r\n    @value=N'Using the GUI to save the table.' , \r\n    @level0type=N'SCHEMA',@level0name=N'ACTIVE', \r\n    @level1type=N'TABLE',@level1name=N'MAKES'\r\nGO\r\n<\/pre>\n<p>Compare this to the syntax used by Oracle PL\/SQL.  I have to say Oracle wins for simplicity on this battle.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"oracle - comments\">\r\n-- Oracle PL\/SQL Syntax\r\nCOMMENT ON TABLE [ACTIVE].[MAKES] IS 'Using the GUI to save the table'; \r\n<\/pre>\n<p>In summary, we can perform many of the Data Definition Language (DDL) tasks with the SQL Server Management Studio (SSMS) graphical interface.  I went over the CREATE TABLE and DROP TABLE commands.  <\/p>\n<p>We started creating our first table named [ACTIVE].[MAKES].  We will use the ALTER TABLE command behind the scenes to build out our table so that it matches my sample T-SQL script.<\/p>\n<p>Next time, I will be talking about administering table permissions 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":[64,753,63,31,752,62,756,12,743,15,755,757,28,741,470,754],"class_list":["post-4418","post","type-post","status-publish","format-standard","hentry","category-db-dev","tag-alter-table","tag-change-tracking-page","tag-create-table","tag-database-developer","tag-designing-tables","tag-drop-table","tag-extended-properties-page","tag-free-code","tag-general-page","tag-john-f-miner-iii","tag-permissions-page","tag-sp_addextendedproperty","tag-sql-server","tag-sql-server-management-studio","tag-ssms","tag-storage-page"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/4418","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=4418"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/4418\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}