SQLServer中创建外键和将txt中的内容导入到数据表中
SQLServer2008下:
1. 创建包含外键的表:
下面列举了两种方式:
create database xiaonei;
--国家表
create table country(
id int
not null primary key identity(1,1),
name varchar(32) not null
);
--省份表
CREATE TABLE province(
id int not null primary key identity(1,1),
name varchar(32) not null,
countryId int REFERENCES country(id) --外键countryId
)
--大学表(大学的公共信息部分)
create table university(
id int not null primary key identity(1,1),
name varchar(64) not null,
countryId int,
proId int,
foreign key (countryId) references country(id), --外键countryId
foreign key (proId) references province(id) --外键proId
)
2. 将txt中的内容导入到数据库表中
txt中的内容:
1 北京
1
2 上海
1
3 天津
1
4 重庆
1
5 黑龙江
1
内容每一行的字段之间是用tab键分隔的,行与行之间是用回车换行符分隔的
将txt拷贝到e:\data\province.txt
在SQLServer中执行命令:
--从txt文件导入数据
bulk insert dbo.province.txt
from 'e:\data\province.txt'
with (
fieldterminator = '\t', --以制表符横向分隔
rowterminator = '\n' --以\n回车换行
)
MySQL中实现上面两个功能的命令是:
1. --省份表
CREATE TABLE province(
id int not null primary key auto_increment,
name varchar(32) not null,
countryId int,
FOREIGN KEY (countryId) REFERENCES country(id)
) TYPE=INNODB
--大学表(大学的公共信息部分)
create table university(
id int not null primary key auto_increment,
name varchar(64) not null,
countryId int,
proId int,
foreign key (countryId) references country(id),
foreign key (proId) references province(id)
)
2. load data local infile 'D:\\data.txt' into table 表名 fields terminated by '\t';
- sqlserver数据导入mysql八: 把sqlserver中的存储过程注释后创建到mysql中(留着人工修改)
- sqlserver数据导入mysql四:给sqlserver中的表创建索引
- sqlserver数据导入mysql八: 把sqlserver中的存储过程注释后创建到mysql中(留着人工修改)
- 如何创建一个与已知的一个表完全相同结构的新表(包括主键、外键、索引),同时将数据导入新表
- 手动创建两个文本文件text1.txt,text2.txt,要求编程创建text3.txt,实现text1.txt和text2.txt文件中除去首行和末尾,其余对应的数据相加,三个文本的内容如下
- sqlserver数据导出为txt文件再导入mysql
- SQLServer将文件下所有的txt内容导入到数据库表
- sqlserver数据导入mysql一: 创建mysql数据库 perl脚本
- sqlserver数据导入mysql一: 创建mysql数据库 perl脚本
- HIVE的安装配置、mysql的安装、hive创建表、创建分区、修改表等内容、hive beeline使用、HIVE的四种数据导入方式、使用Java代码执行hive的sql命令
- mysql创建数据库,创建数据库表导入xlsx、txt文本,查询、删除、插入数据语句的使用
- 在C#中如何动态创建access数据库并对SQLserver中的数据导入进去
- 通过异类查询(OpenDataSource - OLEDB引擎驱动)把外部数据(Excel,TXT)导入到SqlServer及job代理执行出错的处理
- 批量使用mysqlimport将.txt文件数据内容导入数据库
- sqlserver 导入数据出现 无法创建 OLE DB 取值函数。请查看列元数据是否有效
- 数据导入,可以将txt文本文件或excel的内容导入到数据库
- sqlserver数据导入mysql四:给sqlserver中的表创建索引
- SQLServer 工具箱v1.1(SQL脚本排序,清除日志,数据导入导出)附源代码
- mysql命令行导入txt数据