SELECT 열이름1, 열이름2, ... FROM 테이블 이름;
sqlite> select * from bookItem where author = 'lch';
id item author publisher stock
-- ------ ------ ------------ -----
1 python lch digitalbooks 100
3 c# lch hyejiwon 300
4 C++ lch hyejiwon 400
sqlite> select * from bookItem where stock > 200;
id item author publisher stock
-- ---- ------ --------- -----
3 c# lch hyejiwon 300
4 C++ lch hyejiwon 400
sqlite> select * from bookItem where id < 3;
id item author publisher stock
-- ---------- ------ ------------ -----
1 python lch digitalbooks 100
2 javascript kim digitalbooks 200
DELETE FROM 테이블 이름;
DELETE FROM 테이블 이름 WHERE 조건
sqlite> delete from bookItem where stock = 300;
sqlite> select * from bookItem;
id item author publisher stock
-- ---------- ------ ------------ -----
1 python lch digitalbooks 100
2 javascript kim digitalbooks 200
4 C++ lch hyejiwon 400
##############
# 2022.09.28 #
##############
import sqlite3
conn = sqlite3.connect('bookStore')
print('1. DB 연결 성공')
cur = conn.cursor()
print('2. 커서 생성 성공')
cur.execute('create table if not exists bookItem (id int, item char(100), author char(50), publisher char(50), stock int)')
print('3. 테이블 생성')
cur.execute("insert into bookItem values(1, 'java', 'lch', 'ebook', 200)")
cur.execute("insert into bookItem values(2, 'C++', 'kim', 'digital', 300)")
cur.execute("insert into bookItem values(3, 'C#', 'park', 'hanbit', 400)")
cur.execute("insert into bookItem values(4, 'python', 'cho', 'ebook', 500)")
print('4. 데이터 입력')
conn.commit()
print('5. 데이터 저장')
cur.execute("select * from bookItem")
print('6. 데이터 조회')
while True :
row = cur.fetchone()
if(row == None) :
break
print(row)
print('7. 데이터 출력')
conn.close()
print('8. DB 연결 종료')
출력결과
1. DB 연결 성공
2. 커서 생성 성공
3. 테이블 생성
4. 데이터 입력
5. 데이터 저장
6. 데이터 조회
(1, 'java', 'lch', 'ebook', 200)
(2, 'C++', 'kim', 'digital', 300)
(3, 'C#', 'park', 'hanbit', 400)
(4, 'python', 'cho', 'ebook', 500)
7. 데이터 출력
8. DB 연결 종료