실제로는 파일 시스템에 쓰게 되는 것.
스키마(뼈대)라는 개념 : 데이타를 저장할 때에는, 아무렇게나 저장하는 것이 아니라 일정한 형식으로 저장하게 된다. 특정한 형태를 갖고 저장해야만 한다. 랜덤한 데이터가 저장되지 않도록. 기본적으로 노트에 써가면서 만들어가면 안 된다. 모델로 데이타를 접근하는 방법. ORM 중에 여러가지가 있는데 시퀄라이즈에서는 가장 유명함. low query로 먼저 작업하게 됨.
time compexity를 어떻게 줄일 수 있을까? 메세지를 저장하는 구조를 어떻게 바꿀 수 있을까?
파일을 전체를 읽는 상황에서 벗어나야 하기 때문에.
컴퓨터에 삭제는 없다. 포맷이라는 건 0으로 메모리를 채울듯.
ID 값을 가지고 접근할 수 있다
Fixed Width 사이즈가 정해져있다(공간은 부동산)
no SQL은 fix할 필요가 없다
SQL엔 세퍼레이터(구분자)가 없다
모델은 디비를 데려와서 이야기하고
컨트롤러는 모델을 불러와서 이야기하고
classes로 들어오면 라우터를 쓰겠다는 이야기1.
Look at the departments table in the school database provided to you. How many columns does it have and what are the column names?
A : two columns. column name is id & name
Which column in the departments table is intended to be uniquely identifying?
A: id
PRIMARY KEY로 지정하는 경우엔,그 칼럼은 uniquely identifying으로 쓰임. 또한, 다른 테이블에서 참조할 수 있음. 다른 테이블에서 그 칼럼이 참조되는 FOREIGN KEY라고 불린다. 외래 키를 사용하여 다른 곳에 있는 데이터를 가리키는 기술은 관계형 데이터의 가장 기본적인 측면. 서로 다른 두 테이블에 데이터를 저장하는 것이 아니라 다른 테이블의 열에 있는 데이터를 참조하면 동일한 데이터를 두 번 이상 저장할 필요가 없어서 메모리가 절약되고, 데이터를 변경하는 작업 또한 한 곳만 변경하면 되서 단순화 된다.
Look at the teachers 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.
A: department is FOREIGN KEY.
database Query
Display the name column for every row in the students table
A: select name from students;
Display every column for the teachers table. The department column just contains numbers, what are these numbers referencing? (Look at the teachersschema if you need to).
A:select * from teachers; department column from departments table.
Display every column for the teachers table and then every column for the departments table. Just by looking at the tables, what is the name of the department that the teacher beth is a part of?
A:cs
Filtering rows with WHERE
naomi being text, should be placed in single quotes) A :select * from students where name != 'naomi';
A:select name, department from teachers where id > 2 OR name = 'fred'
WHERE pattern matching with LIKE
Display the id and name of all the students whose names end in ‘m’
A:m';
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.”
A:a
Limiting WHERE to a defined set with IN
쿼리를 작성하는 방법은 하나만 이는 것은 아니다.
Display just the names of all the teachers whose id is NOT either 1, 2, or 4
A:SELECT name FROM teachers where id != 1 and id !=2 and id !=4;
select name from teachers where id not IN (1,2,4);
Display just the names of all the teachers whose department is either 1 or 4
A:select name from teachers where id IN (1,4);
Using IN to compose subqueries
Display the name and id of all the teachers in the ‘psy’ department (should be pamela and sunny, with their respective ids)
A:SELECT name, id FROM teachers WHERE department IN (SELECT id FROM departments WHERE name = 'psy');
Display the name of the department that ‘sunny’ teaches for (should be ‘psy’) 헷갈렸음
A:SELECT name FROM departments WHERE id IN (SELECT department FROM teachers WHERE name = 'sunny');
7. Selecting from multiple tables
SELECT departments.id, classes.id FROM departments, classes;
A: 2열column 8행row
SELECT students.*, teachers.name FROM students, teachers;
A: 3열 24행
Advanced filtering with multi-table SELECT
SELECT teachers.name FROM teachers, departments WHERE departments.name = "cs" AND teachers.department = departments.id;You already completed the following with subqueries, now do them without subqueries, using multiple table selection instead.
Display the name and id of all the teachers in the ‘psy’ department (should be pamela and sunny, with their respective ids)
select teachers.name, teachers.id from teachers, departments WHERE teachers.department = departments.id and departments.name = 'psy';
Display the name of the department that ‘sunny’ teaches for (should be ‘psy’)
A:SELECT departments.name from teachers, departments WHERE teachers.department = departments.id and teachers.name = 'sunny';
INNER JOIN
What is the difference between the return from the following two statements:
SELECT * FROM students, teachers;SELECT * FROM students INNER JOIN teachers;A: 차이 없는 것 같다;
Display the name and id of all the teachers in the ‘psy’ department (should be pamela and sunny, with their respective ids)
SELECT teachers.name, teachers.id FROM teachers INNER JOIN departments ON teachers.department = departments.id and departments.name = 'psy'; // and 대신 where
Display the name of the department that ‘sunny’ teaches for (should be ‘psy’)
SELECT departments.name from departments INNER JOIN teachers ON teachers.department = departments.id and teachers.name = 'sunny'; and 대신 where
10. Other joins
?????????
11. Join Tables
Which classes is ‘sam’ taking? (confirm your answer below)
A: communication
SELECT name FROM classes where ID IN (SELECT classes_id from classes_students where student_id IN (SELECT id from students where name = 'sam'));
What are the names of the students in the ‘compromise’ class?
A:naomi,kim,chris // 쿼리로는 모르겠다
What are the names of the students taking any class in the ‘cs’ department?
A:sam을 제외한 전부 // 쿼리로는 모르겠다
SELECT * FROM classes, students;
.mode columncommand and turn headers on with .header on
schema is blueprint
entities == tables;
SQL은 평평한 데이터가 늘어난다. 각 테이블 간의 관계를 정해야 한다.
SQL ARRAY-like id를 가지면 한번에 접근 가능.
SQL은 관계를 가지고 있기 때문에, 많은 것을 한번에 바꿔야 하는 상황이 오면?
SQL은 에러가 잘 나는게 장점. 완전한 관계를 표현해야 하기 때문.
many to many -> one to many로 바꿈
my sql > show tables;
describe(schema) classes;
mysql은 자체의 포트를 갖고 켜지고 포트를 방해할 수 없음.
MUL = foreign key
mysql work bench
sequal pro? - mac
JOIN에는 항상 조건이 필요함.
on 다음에 (조인조건 t.id=c.teacher_id)
읽기보다 쓰는 비용이 더 큼
쿼리문을 잘 작성해서 db에서 머무르는 시간을 줄여야 함
ORM?
QUERY?
ORM 이 훨씬 편함.
쿼리문은 콘솔도 찍을 수 없음. DB 터칭은 늘어날 수 있지만
유지보수와 관리가 쉬움.
쿼리는 개발자의 손을 타지만, ORM은 표준화가 가능.
개발자로 팀에 들어갈때는 ORM을 사용하는 게 좋다.
mysqladmin -u root password ‘wro3o2i@19$2’;