{"id":358,"date":"2020-10-03T21:52:05","date_gmt":"2020-10-03T21:52:05","guid":{"rendered":"https:\/\/kindsonthegenius.com\/mssql\/?p=358"},"modified":"2020-10-03T21:56:58","modified_gmt":"2020-10-03T21:56:58","slug":"ms-sql-server-database-concepts","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/mssql\/ms-sql-server-database-concepts\/","title":{"rendered":"MS SQL Server Database Concepts"},"content":{"rendered":"<p>In this tutorial, we would examine all the MS SQL Server database concepts. We would take a look at all the objects that make up MS SQL server, their definitions and how to create them.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Server Instance<\/strong><\/p>\n<p>A server instance is an installation of an SQL Server. You can have multiple instances on the same machine<\/p>\n<p>To add a new instance to SQL server, run the installer and choose &#8220;<em>New SQL Server stand-alone installation or add features to existing installation<\/em>&#8220;. Then proceed<\/p>\n<figure id=\"attachment_359\" aria-describedby=\"caption-attachment-359\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-359 size-large\" src=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?resize=640%2C485&#038;ssl=1\" alt=\"Adding a new instance to SQL server installation\" width=\"640\" height=\"485\" srcset=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?resize=1024%2C776&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?resize=300%2C227&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?resize=768%2C582&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?resize=1536%2C1164&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.20.45.png?w=1586&amp;ssl=1 1586w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"caption-attachment-359\" class=\"wp-caption-text\">Adding a new instance to SQL server installation<\/figcaption><\/figure>\n<p>An instance has its own separate data files, log files and security credentials.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Database\/Database Server<\/strong><\/p>\n<p>A collection of information organized in such a way that it can easily be managed, accessed and updated.<\/p>\n<p>To create a database, right-click on the database node and select New &gt; Database. Give it a name and OK. In this demo, I called it demodb<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Schema<\/strong><\/p>\n<p>A schema is a collection of database objects such as tables, views, stored procedures, indexes etc. A schema is associated with a user with a username. A schema must always belong to one database. MS SQL has some built in schemas with the same name as the built-in user and roles. For instance: sys, dbo, and INFORMATION_SCHEMA.<\/p>\n<p>To create a new schema.<\/p>\n<p>Expand the database node and right-click on Security &gt; New &gt; Schema<\/p>\n<figure id=\"attachment_360\" aria-describedby=\"caption-attachment-360\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.43.57.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-360 size-medium\" src=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.43.57.png?resize=300%2C260&#038;ssl=1\" alt=\"Creating a new schema in MS SQL\" width=\"300\" height=\"260\" srcset=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.43.57.png?resize=300%2C260&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.43.57.png?resize=768%2C666&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-14.43.57.png?w=786&amp;ssl=1 786w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-360\" class=\"wp-caption-text\">Creating a new schema in MS SQL<\/figcaption><\/figure>\n<p>To reassign an object from on schema to another, use the alter schema statement as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">alter<\/span> <span style=\"color: #008800; font-weight: bold;\">schema<\/span> [<span style=\"color: #008800; font-weight: bold;\">new<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #008800; font-weight: bold;\">schema<\/span>] transfer [<span style=\"color: #008800; font-weight: bold;\">old<\/span><span style=\"color: #333333;\">-<\/span><span style=\"color: #008800; font-weight: bold;\">schema<\/span>].[<span style=\"color: #008800; font-weight: bold;\">object<\/span>]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Table<\/strong><\/p>\n<p>A collection of rows and column\/<\/p>\n<p>To create a new Table, expand the database node, right-click on Table &gt; New &gt; Table<\/p>\n<p>&nbsp;<\/p>\n<p><strong>View<\/strong><\/p>\n<p>A view is a virtual table which is the result of a stored query.<\/p>\n<p>To create a view, expand the database and choose View &gt; New &gt; View<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Stored Procedure<\/strong><\/p>\n<p>A stored procedure is a set of SQL statements stored and executed as group under a given new. Executing a view would return the result of the query execution. A stored procedure can receive input as well as produce outputs.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Login<\/strong><\/p>\n<p>A login is a database object used for authentication into an SQL instance. A login can be associated with multiple users &#8211; one per database.<\/p>\n<p>To create a login, right-click on Security &gt; New &gt; Login.<\/p>\n<p>This would display the New Login dialog box as shown below:<\/p>\n<figure id=\"attachment_361\" aria-describedby=\"caption-attachment-361\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-23.16.47.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-361 size-large\" src=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-23.16.47.png?resize=640%2C553&#038;ssl=1\" alt=\"Creating a New Login in MS SQL Server\" width=\"640\" height=\"553\" srcset=\"https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-23.16.47.png?resize=1024%2C884&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-23.16.47.png?resize=300%2C259&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-23.16.47.png?resize=768%2C663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kindsonthegenius.com\/mssql\/wp-content\/uploads\/sites\/11\/2020\/10\/Screenshot-2020-10-03-at-23.16.47.png?w=1468&amp;ssl=1 1468w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"caption-attachment-361\" class=\"wp-caption-text\">Creating a New Login in MS SQL Server<\/figcaption><\/figure>\n<p>For Windows authentication, then enter or select Login Name or choose it using the Search button<\/p>\n<p>For SQL Server authentication, follow the steps below<\/p>\n<ul>\n<li>go the server properties &gt; Security. Then select SQL Server and Windows Authentication mode under Server Authentication<\/li>\n<li>enter the Login name<\/li>\n<li>enter the password and confirm it<\/li>\n<li>click on the Server Role node and select <em>sysadmin<\/em> under Server roles<\/li>\n<li>go to User Mapping node. Select the database (demodb) and\u00a0 assign it the db_owner role<\/li>\n<li>click on securable and choose the database under the Add Objects pop up<\/li>\n<li>Click OK.<\/li>\n<li>Now you can disconnect and connect using the login you created.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Roles<\/strong><\/p>\n<p>A role is a security principal that is used to manage database or database objects. Some fixed-server roles are provided by MS SQL Server.<\/p>\n<p>&nbsp;<\/p>\n<p>Privileges<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we would examine all the MS SQL Server database concepts. We would take a look at all the objects that make up &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23],"tags":[],"class_list":["post-358","post","type-post","status-publish","format-standard","hentry","category-ms-sql-server"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":2,"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/posts\/358\/revisions\/363"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/mssql\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}