코딩ㆍ개발 정보/데이터베이스 연습

SQLite3 테이블 스키마 확인 방법

RioRex 2023. 3. 2.

SQLite3 테이블 스키마 확인하는 간단한 방법

 

테이블의 스키마에 대한 정보정보만 조회하고자 한다면 SQLite 명령 .schema으로도 확인할 수 있다.

.schema
.schema? TABLE?

인수를 생략하면 모든 테이블과 인덱스의 스키마 정보를 표시한다. 또한 인수에 테이블명을 지정하면 테이블명과 일치하는 테이블과 지정된 테이블명과 관련된 스키마 정보를 표시 할 수 있다.

그럼 .schema 명령을 사용하여 조회해 보도록 하자.

sqlite> .schema
.schema
CREATE TABLE Customers
(
  cust_id      char(10)  NOT NULL ,
  cust_name    char(50)  NOT NULL ,
  cust_address char(50)  NULL ,
  cust_city    char(50)  NULL ,
  cust_state   char(5)   NULL ,
  cust_zip     char(10)  NULL ,
  cust_country char(50)  NULL ,
  cust_contact char(50)  NULL ,
  cust_email   char(255) NULL ,
  PRIMARY KEY (cust_id)
);
CREATE TABLE OrderItems
(
  order_num  int          NOT NULL                      ,
  order_item int          NOT NULL                      ,
  prod_id    char(10)     NOT NULL                      ,
  quantity   int          NOT NULL                      ,
  item_price decimal(8,2) NOT NULL                      ,
  PRIMARY KEY (order_num, order_item)                   ,
  FOREIGN KEY (order_num) REFERENCES Orders (order_num) ,
  FOREIGN KEY (prod_id) REFERENCES Products (prod_id)
);
CREATE TABLE Orders
(
  order_num  int      NOT NULL ,
  order_date datetime NOT NULL ,
  cust_id    char(10) NOT NULL ,
  PRIMARY KEY (order_num)      ,
  FOREIGN KEY (cust_id) REFERENCES Customers (cust_id)
);
CREATE TABLE Products
(
  prod_id    char(10)      NOT NULL ,
  vend_id    char(10)      NOT NULL ,
  prod_name  char(255)     NOT NULL ,
  prod_price decimal(8,2)  NOT NULL ,
  prod_desc  text          NULL     ,
  PRIMARY KEY (prod_id)             ,
  FOREIGN KEY (vend_id) REFERENCES Vendors (vend_id)
);
CREATE TABLE Vendors
(
  vend_id      char(10) NOT NULL ,
  vend_name    char(50) NOT NULL ,
  vend_address char(50) NULL     ,
  vend_city    char(50) NULL     ,
  vend_state   char(5)  NULL     ,
  vend_zip     char(10) NULL     ,
  vend_country char(50) NULL     ,
  PRIMARY KEY (vend_id)
);
sqlite>

 

 

출처: https://www.devkuma.com/docs/sqlite/%ED%85%8C%EC%9D%B4%EB%B8%94-%EC%8A%A4%ED%82%A4%EB%A7%88-%EA%B5%AC%EC%A1%B0-%ED%99%95%EC%9D%B8/

반응형

댓글