Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 dynamically extend the database with import

Author  Topic 

pille
Starting Member

15 Posts

Posted - 2011-03-20 : 01:24:26
hello all
i wrote already about the same subject but to be honest i just do not understand (i perfectly admit it). the merge and bulk import datas just to one table (at lest i cant read anything how to import in more as one table)

i just cant figure it out how to do it. could anybody of you show me the syntax for following example tables (i just need an example so i could extend to my real db)

create Database Logs
go
use Logs
create table DateSet
(
DateSetID int not null identity primary key,
DateSet date not null,
);

create table Data
(
DataID int not null identity primary key,
Data date not null,
);

create table Main
(
MainID int not null identity primary key,
DataID int NOT NULL REFERENCES dbo.Data(DataID),
DateSetID int NOT NULL REFERENCES dbo.DateSet(DateSetID),
);

now the import (not sure is the step correct)
bulk insert temp_import from 'c:\logs.log' with
(
FIELDTERMINATOR = ' ',
ROWTERMINATOR = '\n'
)
GO

the content of logs.log
01.01.2011 data1
02.01.2011 data2
01.01.2011 data3
03.01.2011 data4
01.01.2011 data5
04.01.2011 data4

now, as you thought, in table dateset should be written
01.01.2011
02.01.2011
03.01.2011
04.01.2011
in the table data
data1
data2
data3
data4
data5
and in the main should stand
1 1
2 2
1 3
3 4
1 5
4 4
as you can see / no double values will be imported. the database is normalized - so far

please guys, let me be a part of you thought so i could close my "personal" fight with that challenge :-)
many thanks to you guys and happy sunday

pille
Starting Member

15 Posts

Posted - 2011-03-21 : 21:59:59
update status

i am 1 step further now :-)

i run queries like
insert into Data(Data)
select distinct Data from Temp_Import
where not exists
(
select Data from Data
where Data = Temp_Import.Data
)
go

insert into DateSet(DateSet)
select distinct DateSet from Temp_Import
where not exists
(
select DateSet from DateSet
where DateSet = Temp_Import.DateSet
)
go
these queries sort out the "double" insert problem.
Go to Top of Page

tiffanys110
Starting Member

1 Post

Posted - 2011-03-21 : 23:47:14
i wrote already about the same subject but to be honest i just do not understand (i perfectly admit it). the merge and bulk import datas just to one table (at lest i cant read anything how to import in more as one table)


[url=http://www.acquistareedhardy.com/ed-hardy-negozio.html]ed hardy shop[/url]
[url=http://www.acquistareedhardy.com/ed-hardy.html]ed hardy[/url]
Go to Top of Page
   

- Advertisement -