create database 2.1
DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
use 2.1
;
create table 用户明细
(
用户ID int,
注册日期 date,
身份证号码 varchar(32),
性别 char(4),
出生日期 date,
年龄 int
);
LOAD DATA LOCAL INFILE 'D:\MySQL\2.1\data.txt' INTO TABLE 用户明细
CHARACTER SET 'UTF8'
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
create table 用户明细1
(
用户ID int,
注册日期 date,
身份证号码 varchar(32),
国籍 varchar(32),
性别 char(4),
出生日期 date,
年龄 int
);
错误:不指定列
LOAD DATA LOCAL INFILE 'D:\MySQL\2.1\data.txt' INTO TABLE 用户明细1
CHARACTER SET 'UTF8'
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
正确:指定列导入
LOAD DATA LOCAL INFILE 'D:\MySQL\2.1\data.txt' INTO TABLE 用户明细1
CHARACTER SET 'UTF8'
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(用户ID,注册日期,身份证号码,性别,出生日期,年龄);
create table 用户明细2
(
用户ID int,
注册日期 date,
性别 char(4),
出生日期 date,
年龄 int
);
LOAD DATA LOCAL INFILE 'D:\MySQL\2.1\data.txt' INTO TABLE 用户明细2
CHARACTER SET 'UTF8'
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(用户ID,注册日期,@身份证号码, 性别,出生日期,年龄);
create table 用户明细3
(
用户ID int,
注册日期 date,
性别 char(4),
出生日期 date,
年龄 int
);
LOAD DATA LOCAL INFILE 'D:\MySQL\2.1\data.txt' INTO TABLE 用户明细3
CHARACTER SET 'UTF8'
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(用户ID,注册日期,@身份证号码, 性别,出生日期,@年龄)
set 年龄=TIMESTAMPDIFF(YEAR, 出生日期, now());
SELECT TIMESTAMPDIFF(YEAR,'2012-10-01',now());