Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ImJaeSung
SQL
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
SQL
/
Query_Create table, Insert.sql
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
52 lines (43 loc) · 2.14 KB
main
Breadcrumbs
SQL
/
Query_Create table, Insert.sql
Copy path
Top
File metadata and controls
Code
Blame
52 lines (43 loc) · 2.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# insert, delete, create table
## create table 예를 들어 buy 테이블을 가지고 학습 중 -> create table buy : 같은 테이블을 하나 더 만든다.
## insert 란? buy 테이블에 들어가 있는 값을 우리도 넣는다.
## 테이블 하나 만들기!
create table bda_sql (mem_id int, mem_name char(5), age int);
select * from bda_sql;
## insert 문으로 값을 넣기
insert into bda_sql values(1, '홍길동', 20);
select * from bda_sql;
-- insert into bda_sql values(2, '박길동'); # error 매치가 안되니 매치를 해서 값을 추가해야 한다.
##매치를 통해 두 개의 값만 넣어보자!
insert into bda_sql(mem_id, mem_name) values(2, '박길동');
## auto_increment
## 특정 열을 추가할 때 자동으로 index를 만들어서 추가해 주는 것!
## mem_id 가 숫자형으로 1, 2, 3, 4 증가하는데 계속 insert 사용해야 하는데
## insert auto_increment 사용하면 자동으로 다음 번에는 3이면 -> 4가 값에 입력된다.alter
create table bda_sql2(
mem_id int auto_increment primary key,
mem_name char(5),
age int);
select * from bda_sql2;
insert into bda_sql2 values(null, '홍길동', 20);
insert into bda_sql2 values(null, '박길동', 21);
insert into bda_sql2 values(null, '정길동', 23);
select * from bda_sql2;
## insert 할 때 mem_id를 1000부터 시작하고 싶다.
alter table bda_sql2 auto_increment = 1000; # auto_increment 값을 바꿀 때 사용하는 문법
insert into bda_sql2 values(null, '이길동', 25);
select * from bda_sql2;
## insert 문을 이용해서 하나씩 데이터의 값을 넣었다.
## 기존 테이블의 값을 이용해서 바로 새로운 테이블을 만들 수 있다.
## insert로 값을 계속 넣었는데, 이번에는 다른 테이블에 있는 값을 넣기
create table bda_sql3(
mem_id int auto_increment primary key,
mem_name char(5),
age int);
select * from bda_sql3;
insert into bda_sql3 select mem_id, mem_name, age from bda_sql2;
select * from bda_sql3;
# 후 처리후 현재 테이블에 값을 넣는 것도 가능
select mem_id, mem_name, age from bda_sql2;
select mem_name, avg(age) from bda_sql2
group by mem_name;
You can’t perform that action at this time.