如何将该txt文件作为表格加载到数据库中?

时间:2019-01-31 01:43:03

标签: sql phpmyadmin

我不确定如何将TXT文件作为表格导入或如何:

  1. CustomerPk设置为自动递增
  2. CustNo更改为索引并设置为必填

这是我从我的老师那里获得的TXT文件,任何帮助将不胜感激。我试图只是将文件加载为CSV文件,但是表未正确显示。

CREATE TABLE customer
(   CustomerPK INT(11)
    CustNo          CHAR(8),
        CustFirstName    VARCHAR(20),
        CustLastName     VARCHAR(30),
    CustStreet  VARCHAR(50),
    CustCity    VARCHAR(30),
    CustState   CHAR(2),
    CustZip     CHAR(10),
    CustBal     DECIMAL(12,2) DEFAULT 0,
CONSTRAINT CustomerPK PRIMARY KEY (CustNo)
 )

注释:

  • CustomerPK应该定义为主键,并设置为自动增量
  • CustNo应该定义为索引,并设置为Required
  • CustFirstName应该设置为Required
  • CustLastName应该设置为Required

使用以下SQL语句导入数据:

INSERT INTO customer
    (CustNo, CustFirstName, CustLastName, CustStreet, CustCity,
    CustState, CustZip, CustBal) 
    VALUES('C0954327','Sheri','Gordon','336 Hill St.','Littleton','CO','80129-5543',230.00);

INSERT INTO customer
    (CustNo, CustFirstName, CustLastName, CustStreet, CustCity,
    CustState, CustZip, CustBal) 
    VALUES('C1010398','Jim','Glussman','1432 E. Ravenna','Denver','CO','80111-0033',200.00);

INSERT INTO customer
    (CustNo, CustFirstName, CustLastName, CustStreet, CustCity,
    CustState, CustZip, CustBal) 
    VALUES('C2388597','Beth','Taylor','2396 Rafter Rd','Seattle','WA','98103-1121',500.00);

INSERT INTO customer
    (CustNo, CustFirstName, CustLastName, CustStreet, CustCity,
    CustState, CustZip, CustBal) 
    VALUES('C3340959','Betty','Wise','4334 153rd NW','Seattle','WA','98178-3311',200.00);

INSERT INTO customer
    (CustNo, CustFirstName, CustLastName, CustStreet, CustCity,
    CustState, CustZip, CustBal) 
    VALUES('C3499503','Bob','Mann','1190 Lorraine Cir.','Monroe','WA','98013-1095',0.00);

0 个答案:

没有答案