■ 파이썬 데이터 타입을 사용해 테이블을 생성하는 방법을 보여준다.
▶ 예제 코드 (PY)
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 |
import sqlite3 connection = sqlite3.connect(":memory:") cursor = connection.cursor() cursor.execute("CREATE TABLE TABLE1 (NAME TEXT, AGE INTEGER, MONEY REAL);") cursor.execute("CREATE TABLE TABLE2 (NAME str, AGE int, MONEY float);") cursor.execute("INSERT INTO TABLE1 VALUES ('Tiger', 25, 123.45);") cursor.execute("INSERT INTO TABLE2 VALUES ('Tiger', 25, 123.45);") cursor.execute("SELECT * FROM TABLE1") for rowTuple in cursor: print(rowTuple) print() cursor.execute("SELECT * FROM TABLE2") for rowTuple in cursor: print(rowTuple) """ ('Tiger', 25, 123.45) ('Tiger', 25, 123.45) """ |