{"data":{"site":{"siteMetadata":{"title":"lastrites2018","author":"lastrites2018","siteUrl":"https://lastrites2018.netlify.com","comment":{"disqusShortName":"","utterances":"lastrites2018/gatsby-first-blog"},"sponsor":{"buyMeACoffeeId":""}}},"markdownRemark":{"id":"c19047cf-1663-5963-bb99-e7b428796545","excerpt":"database 실제로는 파일 시스템에 쓰게 되는 것. 스키마(뼈대)라는 개념 : 데이타를 저장할 때에는, 아무렇게나 저장하는 것이 아니라 일정한 형식으로 저장하게 된다. 특정한 형태를 갖고 저장해야만 한다. 랜덤한 데이터가 저장되지 않도록. 기본적으로 노트에 써가면서 만들어가면 안 된다. 모델로 데이타를 접근하는 방법. ORM 중에 여러가지가 있는데 시퀄라이즈에서는 가장 유명함. low query로 먼저 작업하게 됨. DBMS time compexity…","html":"<h2 id=\"database\"><a href=\"#database\" aria-label=\"database permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>database</h2>\n<p>실제로는 파일 시스템에 쓰게 되는 것.</p>\n<p>스키마(뼈대)라는 개념 : 데이타를 저장할 때에는, 아무렇게나 저장하는 것이 아니라 일정한 형식으로 저장하게 된다. 특정한 형태를 갖고 저장해야만 한다. 랜덤한 데이터가 저장되지 않도록. 기본적으로 노트에 써가면서 만들어가면 안 된다. 모델로 데이타를 접근하는 방법. ORM 중에 여러가지가 있는데 시퀄라이즈에서는 가장 유명함. low query로 먼저 작업하게 됨.</p>\n<h2 id=\"dbms\"><a href=\"#dbms\" aria-label=\"dbms permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>DBMS</h2>\n<p>time compexity를 어떻게 줄일 수 있을까? 메세지를 저장하는 구조를 어떻게 바꿀 수 있을까?</p>\n<ul>\n<li>time complexity</li>\n<li>영속적</li>\n</ul>\n<p>파일을 전체를 읽는 상황에서 벗어나야 하기 때문에.</p>\n<p>컴퓨터에 삭제는 없다. 포맷이라는 건 0으로 메모리를 채울듯.</p>\n<h2 id=\"sql-vs-nosql\"><a href=\"#sql-vs-nosql\" aria-label=\"sql vs nosql permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>SQL vs noSQL</h2>\n<p>ID 값을 가지고 접근할 수 있다</p>\n<p>Fixed Width 사이즈가 정해져있다(공간은 부동산)</p>\n<p>no SQL은 fix할 필요가 없다</p>\n<p>SQL엔 세퍼레이터(구분자)가 없다</p>\n<p>모델은 디비를 데려와서 이야기하고</p>\n<p>컨트롤러는 모델을 불러와서 이야기하고</p>\n<div class=\"vp-preview vp-preview-invisible\" data-thumb=\"https://i.vimeocdn.com/video/712712600.webp?mw=3500&amp;mh=2188&amp;q=70\" data-thumb-width=\"3500\" style=\"background-image: url(&quot;https://i.vimeocdn.com/video/712712600.webp?mw=3500&amp;mh=2188&amp;q=70&quot;);\"></div\n<p>classes로 들어오면 라우터를 쓰겠다는 이야기</p>\n<h2 id=\"skool\"><a href=\"#skool\" aria-label=\"skool permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>skool</h2>\n<p>1.</p>\n<ul>\n<li>\n<p>Look at the <code class=\"language-text\">departments</code> table in the <code class=\"language-text\">school</code> database provided to you. How many columns does it have and what are the column names?</p>\n<p>A : two columns. column name is <code class=\"language-text\">id</code> &#x26; <code class=\"language-text\">name</code></p>\n</li>\n<li>\n<p>Which column in the <code class=\"language-text\">departments</code> table is intended to be uniquely identifying?</p>\n<p>A: <code class=\"language-text\">id</code></p>\n</li>\n</ul>\n<p><code class=\"language-text\">PRIMARY KEY</code>로 지정하는 경우엔,그 칼럼은 uniquely identifying으로 쓰임. 또한, 다른 테이블에서 참조할 수 있음. 다른 테이블에서 그 칼럼이 참조되는 <code class=\"language-text\">FOREIGN KEY</code>라고 불린다. 외래 키를 사용하여 다른 곳에 있는 데이터를 가리키는 기술은 관계형 데이터의 가장 기본적인 측면. 서로 다른 두 테이블에 데이터를 저장하는 것이 아니라 다른 테이블의 열에 있는 데이터를 참조하면 동일한 데이터를 두 번 이상 저장할 필요가 없어서 메모리가 절약되고, 데이터를 변경하는 작업 또한 한 곳만 변경하면 되서 단순화 된다.</p>\n<ul>\n<li>\n<p>Look at the <code class=\"language-text\">teachers</code> schema. Which column is being used as a foreign key? Why might we be using a foreign key here rather than storing the data directly in this table? Review the last paragraph if you are unclear.</p>\n<p>A: <code class=\"language-text\">department</code> is FOREIGN KEY.</p>\n</li>\n<li>\n<p>database Query</p>\n</li>\n<li>\n<p>Display the <code class=\"language-text\">name</code> column for every row in the <code class=\"language-text\">students</code> table</p>\n<p>A: select name from students;</p>\n</li>\n<li>\n<p>Display every column for the <code class=\"language-text\">teachers</code> table. The <code class=\"language-text\">department</code> column just contains numbers, what are these numbers referencing? (Look at the <code class=\"language-text\">teachers</code>schema if you need to).</p>\n<p>A:select * from teachers; department column from departments table.</p>\n</li>\n<li>\n<p>Display every column for the <code class=\"language-text\">teachers</code> table and then every column for the <code class=\"language-text\">departments</code> table. Just by looking at the tables, what is the name of the department that the teacher <code class=\"language-text\">beth</code> is a part of?</p>\n<p>A:cs</p>\n</li>\n<li>\n<p>Filtering rows with WHERE</p>\n<ul>\n<li>Display just the name column for all the students whose names are not naomi. (Note, <code class=\"language-text\">naomi</code> being text, should be placed in single quotes)</li>\n</ul>\n<p> A :<code class=\"language-text\">select * from students where name != &#39;naomi&#39;;</code></p>\n<ul>\n<li>Display the name and department id of teachers whose own id is greater than 2 or whose name is ‘fred’</li>\n</ul>\n<p> A:<code class=\"language-text\">select name, department from teachers where id &gt; 2 OR name = &#39;fred&#39;</code></p>\n</li>\n<li>\n<p><strong>WHERE pattern matching with</strong> LIKE</p>\n</li>\n<li>\n<p>Display the id and name of all the students whose names end in ‘m’</p>\n<p>A:<code class=\"language-select id, name from students where name like '\">m&#39;;</code></p>\n</li>\n<li>\n<p>Display all columns for students whose names do not contain the letter ‘a’. HINT: a more long-winded way to say “includes the letter ‘a’” is “includes 0 or more of any letter followed by an ‘a’ followed by 0 or more of any letter.”</p>\n<p>A:<code class=\"language-select * from students where name not like '\">a</code></p>\n</li>\n<li>\n<p><strong>Limiting WHERE to a defined set with</strong> IN</p>\n<p>쿼리를 작성하는 방법은 하나만 이는 것은 아니다.</p>\n</li>\n<li>\n<p>Display just the names of all the teachers whose id is <code class=\"language-text\">NOT</code> either 1, 2, or 4</p>\n<p>A:<code class=\"language-text\">SELECT name FROM teachers where id != 1 and id !=2 and id !=4;</code></p>\n<p><code class=\"language-text\">select name from teachers where id not IN (1,2,4);</code></p>\n</li>\n<li>\n<p>Display just the names of all the teachers whose department is either 1 or 4</p>\n<p>A:<code class=\"language-text\">select name from teachers where id IN (1,4);</code></p>\n</li>\n<li>\n<p><strong>Using IN</strong> <strong>to compose subqueries</strong></p>\n</li>\n<li>\n<p>Display the name and id of all the teachers in the ‘psy’ department (should be pamela and sunny, with their respective ids)</p>\n<p>A:<code class=\"language-text\">SELECT name, id FROM teachers WHERE department IN (SELECT id FROM departments WHERE name = &#39;psy&#39;);</code></p>\n</li>\n<li>\n<p>Display the name of the department that ‘sunny’ teaches for (should be ‘psy’) <strong>헷갈렸음</strong></p>\n<p>A:<code class=\"language-text\">SELECT name FROM departments WHERE id IN (SELECT department FROM teachers WHERE name = &#39;sunny&#39;);</code></p>\n</li>\n</ul>\n<p><strong>7. Selecting from multiple tables</strong></p>\n<ul>\n<li>\n<p><code class=\"language-text\">SELECT departments.id, classes.id FROM departments, classes;</code></p>\n<p>A: 2열column 8행row</p>\n</li>\n<li>\n<p><code class=\"language-text\">SELECT students.*, teachers.name FROM students, teachers;</code></p>\n<p>A: 3열 24행</p>\n</li>\n<li>\n<p>Advanced filtering with multi-table SELECT</p>\n</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT teachers.name FROM teachers, departments WHERE departments.name = &quot;cs&quot; AND teachers.department = departments.id;</code></pre></div>\n<p>You already completed the following with subqueries, now do them without subqueries, using multiple table selection instead.</p>\n<ul>\n<li>\n<p>Display the name and id of all the teachers in the ‘psy’ department (should be pamela and sunny, with their respective ids)</p>\n<p><code class=\"language-text\">select teachers.name, teachers.id from teachers, departments WHERE teachers.department = departments.id and departments.name = &#39;psy&#39;;</code></p>\n</li>\n<li>\n<p>Display the name of the department that ‘sunny’ teaches for (should be ‘psy’)</p>\n<p>A:<code class=\"language-text\">SELECT departments.name from teachers, departments WHERE teachers.department = departments.id and teachers.name = &#39;sunny&#39;;</code></p>\n</li>\n<li>\n<p>INNER JOIN</p>\n</li>\n<li>\n<p>What is the difference between the return from the following two statements:</p>\n<ul>\n<li><code class=\"language-text\">SELECT * FROM students, teachers;</code></li>\n<li><code class=\"language-text\">SELECT * FROM students INNER JOIN teachers;</code></li>\n</ul>\n<p>A: 차이 없는 것 같다;</p>\n</li>\n<li>\n<p>Display the name and id of all the teachers in the ‘psy’ department (should be pamela and sunny, with their respective ids)</p>\n<p><code class=\"language-text\">SELECT teachers.name, teachers.id FROM teachers INNER JOIN departments ON teachers.department = departments.id and departments.name = &#39;psy&#39;;</code> // and 대신 where</p>\n</li>\n<li>\n<p>Display the name of the department that ‘sunny’ teaches for (should be ‘psy’)</p>\n<p><code class=\"language-text\">SELECT departments.name from departments INNER JOIN teachers ON teachers.department = departments.id and teachers.name = &#39;sunny&#39;;</code> and 대신 where</p>\n</li>\n</ul>\n<p><strong>10. Other joins</strong></p>\n<p>?????????</p>\n<p><strong>11. Join Tables</strong></p>\n<ul>\n<li>\n<p>Which classes is ‘sam’ taking? (confirm your answer below)</p>\n<p>A: communication</p>\n<p><code class=\"language-text\">SELECT name FROM classes where ID IN (SELECT classes_id from classes_students where student_id IN (SELECT id from students where name = &#39;sam&#39;));</code></p>\n</li>\n<li>\n<p>What are the names of the students in the ‘compromise’ class?</p>\n<p>A:naomi,kim,chris // 쿼리로는 모르겠다</p>\n</li>\n<li>\n<p>What are the names of the students taking any class in the ‘cs’ department?</p>\n<p>A:sam을 제외한 전부 // 쿼리로는 모르겠다</p>\n</li>\n<li>\n<p><code class=\"language-text\">SELECT * FROM classes, students;</code></p>\n</li>\n</ul>\n<p><code class=\"language-text\">.mode column</code>command and turn headers on with <code class=\"language-text\">.header on</code></p>\n<h2 id=\"schema\"><a href=\"#schema\" aria-label=\"schema permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>schema</h2>\n<p>schema is blueprint</p>\n<p>entities == tables;</p>\n<p>SQL은 평평한 데이터가 늘어난다. 각 테이블 간의 관계를 정해야 한다.</p>\n<p>SQL ARRAY-like id를 가지면 한번에 접근 가능.</p>\n<p>SQL은 관계를 가지고 있기 때문에, 많은 것을 한번에 바꿔야 하는 상황이 오면?</p>\n<p>SQL은 에러가 잘 나는게 장점. 완전한 관계를 표현해야 하기 때문.</p>\n<p>many to many -> one to many로 바꿈</p>\n<p>my sql > show tables;</p>\n<p>describe(schema) classes;</p>\n<p>mysql은 자체의 포트를 갖고 켜지고 포트를 방해할 수 없음.</p>\n<p>MUL = foreign key</p>\n<p>mysql work bench</p>\n<p>sequal pro? - mac</p>\n<p>JOIN에는 항상 조건이 필요함.</p>\n<p>on 다음에 (조인조건 t.id=c.teacher_id)</p>\n<p>읽기보다 쓰는 비용이 더 큼</p>\n<p>쿼리문을 잘 작성해서 db에서 머무르는 시간을 줄여야 함</p>\n<p>ORM?</p>\n<p>QUERY?</p>\n<p>ORM 이 훨씬 편함.</p>\n<p>쿼리문은 콘솔도 찍을 수 없음. DB 터칭은 늘어날 수 있지만</p>\n<p>유지보수와 관리가 쉬움.</p>\n<p>쿼리는 개발자의 손을 타지만, ORM은 표준화가 가능.</p>\n<p>개발자로 팀에 들어갈때는 ORM을 사용하는 게 좋다.</p>\n<p>mysqladmin -u root password ‘wro3o2i@19$2’;</p>","frontmatter":{"title":"Immersive Sprint - database","date":"October 15, 2018"}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"slug":"/til/20181015 IM08D21 database/","previous":{"fields":{"slug":"/til/20181012-20181013 IM08D19-20 web historian/"},"frontmatter":{"title":"Immersive Sprint - web historian","category":"TIL"}},"next":{"fields":{"slug":"/til/20181016 콜백과 모듈/"},"frontmatter":{"title":"콜백과 모듈","category":"TIL"}}}}