SQLServer中创建外键和将txt中的内容导入到数据表中
来源:互联网 发布:装机软件推广联盟 编辑:程序博客网 时间:2024/05/17 01:46
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中创建外键和将txt中的内容导入到数据表中
- 将txt中的数据存到Sql数据表中
- 将TXT文件中的内容正确导入到Excel表格中不混乱的方法
- 将mysql中的数据表导入到hdfs中
- 将数据库中的数据内容写到.txt中
- 将txt中的内容添加到数据库中
- 如何将txt文件里的数据导入到sql数据表中(转)
- 将文本文件导入到Excel数据表中
- 将csv导入到mysql数据表中
- 利用kattle将SQLserver中的数据导入到vertica中
- 将TXT文件按固定长度分列导入到sqlserver中
- 使用企业管理器将txt文件的内容导入到数据库中
- 利用plsql将Excel中的数据导入到oracle数据库的数据表中
- 将SD卡中的txt文件的内容展示到EditText中
- 将excel中的内容导入mysql中
- txt内容通过另存为方式导入到word中
- 将sqlserver中数据导入到oracle数据中
- 将sqlserver中数据导入到oracle数据中
- 关于C++语言的一些小知识点
- ios textField 输入值监听
- 命名(code)
- 新手福利:Apache Spark 入门攻略
- java后台模拟访问url获取数据
- SQLServer中创建外键和将txt中的内容导入到数据表中
- iOS开发常见正则表达式
- NYOJ 214 最长上升子序列加强版(二分+dp)
- ESP && EBP
- codevs-1085 数字游戏
- Android4.4设置状态栏为透明
- Json 介绍
- Linux——琐碎
- Java安全学习笔记(一)--凯撒密码