{"id":476,"date":"2016-05-08T11:34:50","date_gmt":"2016-05-08T16:34:50","guid":{"rendered":"https:\/\/researchbdev.wpengine.com\/digital-computational-studies\/?p=476"},"modified":"2017-04-20T09:22:19","modified_gmt":"2017-04-20T14:22:19","slug":"sequel-pro-creating-a-database","status":"publish","type":"post","link":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/student-research\/sql\/sequel-pro-creating-a-database\/","title":{"rendered":"Sequel Pro: Creating a Database"},"content":{"rendered":"<p>This walkthrough\u00a0has been created using <a href=\"http:\/\/joshualande.com\/create-tables-sql\/\">this tutorial<\/a> as a resource.<\/p>\n<ol>\n<li>Start your machine&#8217;s MySQL Server instance through System Preferences. \u00a0See<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/student-research\/sql\/mysql-download-and-setup-mac-os-x\/\"> this walkthrough<\/a> for assistance in doing so.<\/li>\n<li>Download Sequel Pro <a href=\"http:\/\/www.sequelpro.com\/download\">here<\/a>.<\/li>\n<li>Open Sequel Pro.<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-8.33.09-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-478 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-8.33.09-PM.png\" alt=\"Screen Shot 2016-04-24 at 8.33.09 PM\" width=\"924\" height=\"630\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-8.33.09-PM.png 924w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-8.33.09-PM-300x205.png 300w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-8.33.09-PM-250x170.png 250w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-8.33.09-PM-624x425.png 624w\" sizes=\"auto, (max-width: 924px) 100vw, 924px\" \/><\/a><\/li>\n<li>Create a Standard connection to your MySQL Server, using IP address 127.0.0.1 as the Host and your MySQL root credentials for the Username and Password. \u00a0No extra information is necessary.<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-9.16.37-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-481 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-9.16.37-PM.png\" alt=\"Screen Shot 2016-04-24 at 9.16.37 PM\" width=\"468\" height=\"406\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-9.16.37-PM.png 468w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-9.16.37-PM-300x260.png 300w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-24-at-9.16.37-PM-250x217.png 250w\" sizes=\"auto, (max-width: 468px) 100vw, 468px\" \/><\/a><\/li>\n<li>Once connected,\u00a0you will automatically be in the &#8220;Query&#8221; section of Sequel Pro, where you will type and run MySQL commands. \u00a0In this demo, I will create a database of classmates, but feel free to mimic the syntax used in order to create a database of your choosing. \u00a0To create your database, type <strong>CREATE DATABASE classmate_database;\u00a0<\/strong>then press &#8220;Run Previous&#8221; just below in order to run your code and create your database.<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.40.47-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-488 alignnone\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.40.47-PM.png\" alt=\"Screen Shot 2016-04-26 at 8.40.47 PM\" width=\"676\" height=\"281\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.40.47-PM.png 676w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.40.47-PM-300x125.png 300w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.40.47-PM-250x104.png 250w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.40.47-PM-624x259.png 624w\" sizes=\"auto, (max-width: 676px) 100vw, 676px\" \/><\/a>To check that you&#8217;ve successfully created the database, navigate to the &#8220;TABLES&#8221; section of the Sequel Pro window\u00a0and locate <strong>classmate_database<\/strong>.<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.43.40-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-493 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.43.40-PM.png\" alt=\"Screen Shot 2016-04-26 at 8.43.40 PM\" width=\"183\" height=\"137\" \/><\/a><\/li>\n<li>In order to work with the database your have just created, use the command &#8220;USE&#8221; and type <strong>USE classmate_database;<\/strong> and run the command just as you did before.<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.49.41-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-489 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.49.41-PM.png\" alt=\"Screen Shot 2016-04-26 at 8.49.41 PM\" width=\"252\" height=\"36\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.49.41-PM.png 252w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.49.41-PM-250x36.png 250w\" sizes=\"auto, (max-width: 252px) 100vw, 252px\" \/><\/a><\/li>\n<li>Now, you&#8217;ll need to create a table in order to add some actual content to your database. \u00a0To learn more about the organization of a database or, more specifically, the relationship between a database and its tables, check out this post. \u00a0To create the table, unsurprisingly, we&#8217;ll use the command &#8220;CREATE TABLE&#8221; to create a table of classmates and proceed to indicate the primary key column and an initial (unique) column for the database. \u00a0Type and run the following code:<br \/>\n<strong>CREATE TABLE classmates (<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 student_id INT NOT NULL,<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 student_lastName VARCHAR(30) NOT NULL,<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 PRIMARY KEY (student_id),<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 UNIQUE (student_lastName)<\/strong><br \/>\n<strong>);<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.24.17-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-496 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.24.17-PM.png\" alt=\"Screen Shot 2016-04-26 at 9.24.17 PM\" width=\"289\" height=\"90\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.24.17-PM.png 289w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.24.17-PM-250x78.png 250w\" sizes=\"auto, (max-width: 289px) 100vw, 289px\" \/><\/a><a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-8.43.22-PM.png\"><br \/>\n<\/a><\/strong>Let&#8217;s take some time to understand the code we&#8217;ve just used. \u00a0<strong>CREATE DATABASE<\/strong> is self explanatory; however, it&#8217;s important to notice\u00a0the way we set student_id as the <strong>PRIMARY KEY<\/strong> here and set student_lastName as a <strong>UNIQUE<\/strong> key. \u00a0Both primary and unique keys are indices whose members must all be unique. \u00a0Here, that means that no students can have the same ID and that no students can have the same last name (which may not be a realistic assumption). \u00a0The primary key is special in that it is used for identification. \u00a0In student_id, <strong>INT<\/strong> specifies that the column&#8217;s values will be integers and <strong>NOT NULL<\/strong> indicates that the value cannot be null. \u00a0If a null value is attempted for this column, an error will occur. \u00a0In student_lastName, <strong>VARCHAR(30)<\/strong> specifies that the column&#8217;s value will be composed characters with a maximum length of 30. \u00a0Here, VARCHAR is used instead of MySQL&#8217;s CHAR because VARCHAR allows user to indicate a string of variable length, while CHAR&#8217;s declaration indicates a string of static length. \u00a0We use VARCHAR here so that last names of different lengths can be inserted into the column.<\/li>\n<li>Now is a good time to check that your table has been created. \u00a0Click on the &#8220;Content&#8221; button on the top toolbar on the Sequel Pro window. \u00a0If you find <strong>student_id<\/strong> and <strong>student_lastName\u00a0<\/strong>as columns, you have successfully created the beginnings of your database!<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.53.31-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-498 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.53.31-PM.png\" alt=\"Screen Shot 2016-04-26 at 9.53.31 PM\" width=\"609\" height=\"166\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.53.31-PM.png 609w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.53.31-PM-300x82.png 300w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-9.53.31-PM-250x68.png 250w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/a>You can resume coding by returning to the &#8220;Query&#8221; button on the top toolbar.<\/li>\n<li>Now, let&#8217;s add some actual values to our table using the &#8220;INSERT INTO&#8221; and &#8220;VALUES&#8221; command by typing and running the following code:<br \/>\n<strong>INSERT INTO classmates<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 (student_id, student_lastName)<\/strong><br \/>\n<strong>VALUES<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 (1, &#8220;Lastname1&#8221;),<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 (2, &#8220;Lastname2&#8221;),<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 (3, &#8220;Lastname3&#8221;);<br \/>\n<\/strong>Be sure to contain the last name values in quotes and to assign unique id number values to each student.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-500 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-10.06.35-PM.png\" alt=\"Screen Shot 2016-04-26 at 10.06.35 PM\" width=\"251\" height=\"87\" srcset=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-10.06.35-PM.png 251w, https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-10.06.35-PM-250x87.png 250w\" sizes=\"auto, (max-width: 251px) 100vw, 251px\" \/>To check to make sure that your data was entered correctly, again navigate to the &#8220;Content&#8221; button. \u00a0If you click to drop the <strong>student_id<\/strong> or <strong>student_lastName<\/strong> columns down, you should find your data!<br \/>\n<a href=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-10.06.50-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-501 aligncenter\" src=\"https:\/\/research.bowdoin.edu\/digital-computational-studies\/files\/2016\/04\/Screen-Shot-2016-04-26-at-10.06.50-PM.png\" alt=\"Screen Shot 2016-04-26 at 10.06.50 PM\" width=\"237\" height=\"133\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This walkthrough\u00a0has been created using this tutorial as a resource. Start your machine&#8217;s MySQL Server instance through System Preferences. \u00a0See this walkthrough for assistance in doing so. Download Sequel Pro here. Open Sequel Pro. Create a Standard connection to your MySQL Server, using IP address 127.0.0.1 as the Host and your MySQL root credentials for [&hellip;]<\/p>\n","protected":false},"author":106,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[17],"tags":[],"class_list":{"0":"post-476","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-sql","7":"entry"},"_links":{"self":[{"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/users\/106"}],"replies":[{"embeddable":true,"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":0,"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"wp:attachment":[{"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/media?parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/research.bowdoin.edu\/digital-computational-studies\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}