{"id":59,"date":"2016-05-18T00:16:28","date_gmt":"2016-05-18T07:16:28","guid":{"rendered":"https:\/\/database.guide\/?p=59"},"modified":"2020-02-14T16:35:18","modified_gmt":"2020-02-14T23:35:18","slug":"how-to-create-a-database-in-sql-server","status":"publish","type":"post","link":"https:\/\/database.guide\/how-to-create-a-database-in-sql-server\/","title":{"rendered":"How to Create a Database in SQL Server"},"content":{"rendered":"<p>To create a <a href=\"https:\/\/database.guide\/what-is-a-database\/\">database<\/a> in <a href=\"https:\/\/database.guide\/what-is-sql-server\/\">SQL Server<\/a> using the GUI:<\/p>\n<ol>\n<li>From the Object Explorer, right click on\u00a0<kbd>Databases<\/kbd>\u00a0and select <kbd>New database...<\/kbd><\/li>\n<li>Name the database, adjust settings if\u00a0required, then click <kbd>OK<\/kbd><\/li>\n<\/ol>\n<p>Once you&#8217;ve created the database, you can create <a href=\"https:\/\/database.guide\/what-is-a-table\/\">tables<\/a> and other database objects. You can also modify any database properties as required.<\/p>\n<p><!--more--><\/p>\n<p>Below are\u00a0screenshots for the above steps.<\/p>\n<h2>The Object Explorer<\/h2>\n<p>From the Object Explorer, right click on\u00a0<kbd>Databases<\/kbd>\u00a0and select <kbd>New database...<\/kbd>:<\/p>\n<figure id=\"attachment_269\" aria-describedby=\"caption-attachment-269\" style=\"width: 290px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-269\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_1.png\" alt=\"Screenshot of right-clicking on the Object Explorer in SQL Server 2014.\" width=\"300\" height=\"204\" \/><\/a><figcaption id=\"caption-attachment-269\" class=\"wp-caption-text\">Right-clicking on an option in the Object Explorer usually brings up a contextual menu that enables you to choose an option.<\/figcaption><\/figure>\n<h2>Name the Database<\/h2>\n<p>Name the database, adjust settings as required, then click <kbd>OK<\/kbd>:<\/p>\n<figure id=\"attachment_275\" aria-describedby=\"caption-attachment-275\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-275\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_2.png\" alt=\"Screenshot of the New Database dialog in SQL Server 2014\" width=\"600\" height=\"537\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_2.png 600w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_2-300x269.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-275\" class=\"wp-caption-text\">The &#8220;New Database&#8221; dialog in SQL Server 2014. Here you provide a name for the database and adjust other settings if required.<\/figcaption><\/figure>\n<p>The database will now appear in the Object Explorer\u00a0under <samp>Databases<\/samp>.<\/p>\n<h2>Database Properties<\/h2>\n<p>You can adjust the database properties by right-clicking on the database in the Object Explorer:<\/p>\n<figure id=\"attachment_276\" aria-describedby=\"caption-attachment-276\" style=\"width: 190px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-276 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_5.png\" alt=\"Screenshot of right-clicking on a database in the Object Browser in SQL Server 2014.\" width=\"200\" height=\"269\" \/><\/a><figcaption id=\"caption-attachment-276\" class=\"wp-caption-text\">Right-clicking on the database in the Object Explorer opens a contextual menu that you can select properties and other options from.<\/figcaption><\/figure>\n<p>This brings up the Database Properties dialog:<\/p>\n<figure id=\"attachment_277\" aria-describedby=\"caption-attachment-277\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-277 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_6.png\" alt=\"Screenshot of Database Properties dialog in SQL Server 2014.\" width=\"600\" height=\"539\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_6.png 600w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_database_sql_server_2014_6-300x270.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-277\" class=\"wp-caption-text\">The Database Properties dialog box allows you to configure the properties of your database. You can find a property by selecting the applicable page from the left menu.<\/figcaption><\/figure>\n<h2>The Model Database<\/h2>\n<p>When you create your database, it uses the <strong>model<\/strong> database as a template.<\/p>\n<p>The\u00a0<strong>model<\/strong> database is created when you install SQL Server. You can see the database in the list of databases in the Object Explorer\u00a0even before you create your first database.<\/p>\n<p>If you create new databases regularly, and immediately find yourself having to modify them with the same changes each time, you can modify the <strong>model<\/strong> database to incorporate those changes.\u00a0You will no longer need to modify every database you create with the same changes.<\/p>\n<p>For example, you could set permissions, add objects such as tables, functions, or <a href=\"https:\/\/database.guide\/what-is-a-stored-procedure\/\">stored procedures<\/a>, and more.<\/p>\n<h3>Restrictions of the Model Database<\/h3>\n<p>However, there are some tasks that can&#8217;t be performed on the <strong>model<\/strong> database. As of SQL Server 2016 these <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/ms186388(v=sql.130).aspx\">are<\/a>:<\/p>\n<ul>\n<li>Adding files or filegroups.<\/li>\n<li>Changing collation. The default collation is the server collation.<\/li>\n<li>Changing the database owner. <strong>model<\/strong> is owned by <strong>sa<\/strong>.<\/li>\n<li>Dropping the database.<\/li>\n<li>Dropping the <strong>guest<\/strong> user from the database.<\/li>\n<li>Enabling change data capture.<\/li>\n<li>Participating in database mirroring.<\/li>\n<li>Removing the primary filegroup, primary data file, or log file.<\/li>\n<li>Renaming the database or primary filegroup.<\/li>\n<li>Setting the database to OFFLINE.<\/li>\n<li>Setting the primary filegroup to READ_ONLY.<\/li>\n<li>Creating procedures, views, or triggers using the WITH ENCRYPTION option. The encryption key is tied to the database in which the object is created. Encrypted objects created in the <strong>model<\/strong> database can only be used in <strong>model<\/strong>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To create a database in SQL Server using the GUI: From the Object Explorer, right click on\u00a0Databases\u00a0and select New database&#8230; Name the database, adjust settings if\u00a0required, then click OK Once you&#8217;ve created the database, you can create tables and other database objects. You can also modify any database properties as required.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[11,10,12],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-sql-server","tag-create-database","tag-how-to","tag-sql-server"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":9,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":733,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/59\/revisions\/733"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}