Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 티스토리챌린지
- 문자열
- pointer
- Data Science
- array
- 파이썬
- raw data
- 반복문
- Object Oriented Programming
- vscode
- 함수
- function
- 포인터
- Deep Learning
- baekjoon
- string
- assignment operator
- 알고리즘
- Class
- 배열
- Pre-processing
- 오블완
- Python
- programming
- 백준
- pass by reference
- C++
- predictive analysis
- OOP
- const
Archives
- Today
- Total
Channi Studies
[MySQL] Day 10. AUTO_INCREMENT attribute 본문
AUTO_INCREMENT attribute can be applied to a column that is set as a key.
Whenever we insert a new row, the primary key will be populated automatically.
Let's re-create the transactions table that we created before.
DROP TABLE transactions;
CREATE TABLE transactions(
transaction_id INT PRIMARY KEY AUTO_INCREMENT,
amount DECIMAL(5, 2)
);

We can verify AUTO_INCREMENT attribute applied in the object info.
Now transaction_id column will start from data of 1, and incremenet by 1 each row.
Let's try inserting a row.
INSERT INTO transactions (amount)
VALUES (4.99);
SELECT * FROM transactions;

Let's adding 2 more rows.
INSERT INTO transactions (amount)
VALUES (2.89), (1.99);
SELECT * FROM transactions;

It will continue to increment by 1 for each new row insertions.
We can also set the starting number of the AUTO_INCREMENT.
Let's drop all the rows first, and type following:
DELETE FROM transactions;
ALTER TALBE transactions
AUTO_INCREMENT = 1000;
Now let's try adding some rows to check how it has changed now.
INSERT INTO transactions(amount)
VALUES (1.49), (2.49), (3.49), (4.49);
SELECT * FROM transactions;

여전히 increment는 1씩 되지만, 시작 지점이 1000으로 바뀐 것을 확인할 수 있습니다.
'SQL' 카테고리의 다른 글
| [MySQL] Day 12. JOINS (INNER JOIN, LEFT JOIN, RIGHT JOIN) (0) | 2025.04.09 |
|---|---|
| [MySQL] Day 11. FOREIGN KEY constraint (0) | 2025.04.07 |
| [MySQL] Day 9. PRIMARY KEYS constraint (0) | 2025.04.06 |
| [MySQL] Day 8. DEFAULT Constraint (0) | 2025.04.03 |
| [MySQL] Day 7. CHECK Constraint (0) | 2025.04.02 |