개념정리
ERD(Entity Relationship Diagram)
- 테이블간의 관계를 설명해주는 다이어그램
- 개체(entity)와 속성(attribute), 관계성(relationship) 을 표현한다.
- 프로젝트에서 사용되는 DB의 구조를 한눈에 파악할 수 있다. 즉, API를 효율적으로 뽑아내기 위한 모델 구조도.
[DataBase] ERD란?
https://velog.io/@kjhxxxx/DataBase-ERD%EB%9E%80
[DataBase] ERD란?
[DataBase] ERD란?
velog.io
https://mslilsunshine.tistory.com/164
ERD, 어떻게 설계하는 걸까?
🧐 What is ERD? 우선, ERD가 무엇인지 부터 짚고 넘어가자. ERD란 Entity Relationship Diagram의 약어로, 데이터베이스 구조를 한눈에 알아보기 위해서 쓰인다. DB를 개발하기 전에 보다 많은 아이디어를 도
mslilsunshine.tistory.com
https://woongsin94.tistory.com/186
ER 다이어그램(ER Diagram)
1. 정의 ER diagram 이란 Entity-Relationship Model을 표현하는 것으로, 현실세계의 요구사항(Requirements)들로 부터 Database를 설계과정에서 활용된다. 즉, 개념을 모델링하는 것으로 개체(entity)와 속성(attribut
woongsin94.tistory.com
DBMS( Database Management system )
- 저장소에 여러 사용자가 접근하여 데이터를 저장 및 관리 등의 기능을 수행하며 공유할 수 있는 환경을 제공하는 응용 소프트웨어 프로그램
- 관계형DB , 객체지향DB , 분산DB , 데이터웨어하우스 , NosqlDB....
관계형DB
- 테이블이 다른 테이블들과 관계를 맺고 모여있는 집합체
프로젝트
ERD 작성및 활용
- 자기만의 테이블 구조를 설계해보자
- ERD 만들수있고 , CRUD 구현 , .....
- REST API로 노드.JS연결
ERD 예시
https://opentextbc.ca/dbdesign01/back-matter/appendix-b-erd-exercises/
Appendix B Sample ERD Exercises – Database Design – 2nd Edition
Appendix B Sample ERD Exercises Exercise 1 Manufacturer A manufacturing company produces products. The following product information is stored: product name, product ID and quantity on hand. These products are made up of many components. Each component can
opentextbc.ca
https://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html
Introduction to Database Design | Tutorial | Datanamic
Introduction to Database Design This article/tutorial will teach the basis of relational database design and explains how to make a good database design. It is a rather long text, but we advise to read all of it. Designing a database is in fact fairly easy
www.datanamic.com
https://velog.io/@jhyeom1545/ERD-ujz8ss06
[DB, SQL] ERD
DB 구조를 만들기 위한 ERD
velog.io
1. ERD 작성
https://www.erdcloud.com/d/5wYvR8TAq37KFJ82q
2. Node.js 에서 MySQL 테이블 생성.
workbench에서 새로운 데이터베이스 만든다.
[참고]
npm init -y
npm i mysql2
npm i -D nodemon
// package.json 에서 스크립트 란에 "start": "nodemon app" 문구 추가
npm run start
app.js 에 해당 스크립트 작성.
// 코드를 입력하세요.
var mysql = require('mysql2'); //커넥션 에러 (플러그인)
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "1111",
database: "new_schema"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "CREATE TABLE customers (name VARCHAR(255), address VARCHAR(255))";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Table created");
});
});
데이터 베이스를 생성하고 진행해야한다.
C:\Users\user\Desktop\test\app.js:13
if (err) throw err;
^
Error: Unknown database 'new_schema'
.....
code: 'ER_BAD_DB_ERROR',
errno: 1049,
sqlState: '42000',
sqlMessage: "Unknown database 'new_schema'",
sql: undefined
참고
저장 프로시저
https://devkingdom.tistory.com/323
테이블 삭제
// sql 변수에 해당 문장을 새로 할당한다.
var sql = "DROP TABLE customers";
테이블 생성시 내용을 입력해야한다.
Error: A table must have at least one visible column.
....
code: undefined,
errno: 4028,
sqlState: 'HY000',
sqlMessage: 'A table must have at least one visible column.',
sql: 'CREATE TABLE endmill_info'
내용 삽입
var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')"
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
MySQL에서 밸류 확인
select * from new_schema.customers
테이블에서 value 삭제
var sql = "DELETE FROM customers WHERE address = 'Mountain 21'";
// customers 테이블에 있는 속성중 address = Mountain 21 이면 해당 밸류를 삭제.
con.connect(function(err) {
if (err) throw err;
var sql = "DELETE FROM customers WHERE address = 'Mountain 21'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
});
db 정규화
'database' 카테고리의 다른 글
데이터베이스 (DB) - MongoDB (1) (0) | 2023.05.03 |
---|---|
데이터베이스 (DB) - MongoDB (2) (0) | 2023.05.02 |
데이터베이스 (DB) - MySQL (3) (0) | 2023.05.02 |
데이터베이스 (DB) - MySQL (2) (0) | 2023.05.02 |
데이터베이스 (DB) - MySQL (1) (0) | 2023.05.01 |