Showing posts with label old. Show all posts
Showing posts with label old. Show all posts

Tuesday, March 27, 2012

Bulk Inserting Data into a new table with different ID's that need to be changed

Hi

I have a system which Profiles people. However a new profiler has been written which is better, and all the old profiled members have to be moved to the new profiler tables.

I have a Members table with member data in it, it contains the old profile data in the table too, or at least the ID's per member.

In the new profiler things work slightly different.

I'll give an example:

Lets say MemberID 3241 is a smoker, SmokerID = 3 (Moderate Smoker)

And he drinks occasionally, AlcoholID = 2 (Light)

These ID fields are kept in the Members table which link to a table of their own i.e. memSmoking Table, or memAlcohol Table

The new profiler table works different. In the sense that the Alcohol and Smoking are all in the same table, but with different OptionID's and ValuesID's

Here is some sample code that i wrote. Just copy and paste, it will give you a base to work from. I'm trying my best to supply as much information as possible, so if i left anything out then please let me know? And thanks for the help in advance

Code Snippet

--Sample Code:

--Members Table

DECLARE @.Members TABLE (MemberID INT IDENTITY(1,1),

ClientID INT,

Name VARCHAR(50),

Surname VARCHAR(50),

GenderID CHAR(1),

MaritalStatusID INT,

MemSmokingID INT,

MemAlcoholID INT)

INSERT INTO @.Members VALUES (211, 'Carel','Greaves', 'M', 2, 1, 3)

INSERT INTO @.Members VALUES (211, 'Jill', 'Jenkins', 'F', 1, 3, 4)

SELECT * FROM @.Members

--

--Profile Attrubutes

--

DECLARE @.memGender TABLE (GenderID CHAR(1), Description VARCHAR(50))

INSERT INTO @.memGender VALUES ('M', 'Male')

INSERT INTO @.memGender VALUES ('F', 'Female')

SELECT * FROM @.memGender

DECLARE @.memMaritalStatus TABLE (MaritalStatusID INT, Description VARCHAR(50))

INSERT INTO @.memMaritalStatus VALUES (1, 'Married')

INSERT INTO @.memMaritalStatus VALUES (2, 'Single')

INSERT INTO @.memMaritalStatus VALUES (3, 'Devorced')

INSERT INTO @.memMaritalStatus VALUES (4, 'Widowed')

SELECT * FROM @.memMaritalStatus

DECLARE @.memSmoke TABLE (MemSmokingID INT, Description VARCHAR(50))

INSERT INTO @.memSmoke VALUES (1, 'Nil')

INSERT INTO @.memSmoke VALUES (2, 'Light')

INSERT INTO @.memSmoke VALUES (3, 'Moderate')

INSERT INTO @.memSmoke VALUES (4, 'Heavy')

SELECT * FROM @.memSmoke

DECLARE @.memAlcohol TABLE (MemAlcoholID INT, Description VARCHAR(50))

INSERT INTO @.memAlcohol VALUES (1, 'Nil')

INSERT INTO @.memAlcohol VALUES (2, 'Light')

INSERT INTO @.memAlcohol VALUES (3, 'Moderate')

INSERT INTO @.memAlcohol VALUES (4, 'Heavy')

SELECT * FROM @.memAlcohol

--

--New Profile Attributes

--

DECLARE @.MemberOptionAtributes TABLE (ValuesID INT IDENTITY(1,1),

OptionID INT,

DisplayName VARCHAR(50))

INSERT INTO @.MemberOptionAtributes VALUES (2, 'Male')

INSERT INTO @.MemberOptionAtributes VALUES (2, 'Female')

INSERT INTO @.MemberOptionAtributes VALUES (3, 'Married')

INSERT INTO @.MemberOptionAtributes VALUES (3, 'Single')

INSERT INTO @.MemberOptionAtributes VALUES (3, 'Devorced')

INSERT INTO @.MemberOptionAtributes VALUES (3, 'Widowed')

INSERT INTO @.MemberOptionAtributes VALUES (4, 'Nil')

INSERT INTO @.MemberOptionAtributes VALUES (4, 'Light')

INSERT INTO @.MemberOptionAtributes VALUES (4, 'Moderate')

INSERT INTO @.MemberOptionAtributes VALUES (4, 'Heavy')

INSERT INTO @.MemberOptionAtributes VALUES (5, 'Nil')

INSERT INTO @.MemberOptionAtributes VALUES (5, 'Light')

INSERT INTO @.MemberOptionAtributes VALUES (5, 'Moderate')

INSERT INTO @.MemberOptionAtributes VALUES (5, 'Heavy')

SELECT * FROM @.MemberOptionAtributes

--MemberProfileLookupValues Table

DECLARE @.MemberProfileLookupValues TABLE (EntryID INT IDENTITY(1,1),

MemberID INT,

OptionID INT,

ValueID INT)

--This is how the data should be inserted, but i don't know how to do it in bulk for all the members in the members table (There are over 1000000)!

INSERT INTO @.MemberProfileLookupValues VALUES (1, 1, 1)

INSERT INTO @.MemberProfileLookupValues VALUES (1, 3, 5)

INSERT INTO @.MemberProfileLookupValues VALUES (1, 4, 7)

INSERT INTO @.MemberProfileLookupValues VALUES (1, 5, 13)

INSERT INTO @.MemberProfileLookupValues VALUES (2, 1, 2)

INSERT INTO @.MemberProfileLookupValues VALUES (2, 3, 3)

INSERT INTO @.MemberProfileLookupValues VALUES (2, 4, 9)

INSERT INTO @.MemberProfileLookupValues VALUES (2, 5, 14)

SELECT * FROM @.MemberProfileLookupValues

--Here is a piece of actual code that i tried that i thought would work but it inserted all the fields for all options for all members (WHOOPS!)

/*SET NOCOUNT ON

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

SELECT M.MemberID, '6', CASE M.MaritalStatusID WHEN 1 THEN '7'

WHEN 2 THEN '8'

WHEN 3 THEN '9'

WHEN 4 THEN '10'

END

FROM Members M

INNER JOIN _MemberProfileLookupValues ML ON M.MemberID = ML.MemberID

WHERE M.Active = 1

AND ML.OptionID <> 6

GO

*/

Carel:

What is the objective here; I am afraid I missed it.

|||

Old Profiler uses these tables

@.Members

@.memSmoking

@.memAlcohol

@.memMaritalStatus

New Profiler uses these Tables

@.MemberOptionAtributes

@.MemberProfileLookupValues

So the memberID From the @.members table has to be inserted into the @.memberProfileLookupValues table, where the OptionID matched the type of attribute i.e. Smoking, Alcohol etc

Smoking = OptionID (4 in this case) i get the OptionID values from the @.MemberOptionAtributes table

Alcohol = OptionID (5 in this case) i also get the OptionID values from the @.MemberOptionAttributes table

When it comes to the memory tables i created, just look at the INSERT STATEMENT for the @.MemberProfileLookupValues table at the bottom and compare to the fields in the @.Members table.

OptionID's Come from the @.MemberOptionAtributes table. The valuesID's just have to be set to the right places.

for example:

If you look at the memSmoking Table

it has 4 ID's

1

2

3

4

In the @.MemberOptionAtributes table the OptionID for Smoking is 4

as far as the values are concerned for smoking in the MemberOptionAtributes table

@.memSmoking .memSmokingID(1) = @.MemberOptionAtributes .ValueID(7)

@.memSmoking .memSmokingID(2) = @.MemberOptionAtributes .ValueID(8)

@.memSmoking .memSmokingID(3) = @.MemberOptionAtributes .ValueID(9)

@.memSmoking .memSmokingID(4) = @.MemberOptionAtributes .ValueID(10)

I hope this helps, i'll keep trying to give as much info as possible.

Kind Regards

Carel Greaves

=== Edited by Carel Greaves @. 23 Jun 2007 9:32 PM UTC===

This was the porst that i posted yesterday, i sat thinking about the problem again today, and came up with something that might help me a little more, and maybe unconfuse the situation.

I want to insert all the generated memberID's in the members table into the @.MemberProfileLookupValues table with the AlcoholID's and MemSmokingID's

Hovever the New Profiler accepts the MemberID, OptionID, and ValuesID
Where the old way it was done was basically a pivotted way of doing it, i'm basically just un-pivvotting the table in the new table.

--Real Code that i actually used.
INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)
SELECT m.MemberID, '12', CASE MC.HealthInterestID
WHEN 1 THEN '71'
WHEN 2 THEN '72'
WHEN 3 THEN '73'
WHEN 4 THEN '74'
WHEN 5 THEN '75'
WHEN 6 THEN '76'
WHEN 7 THEN '77'
WHEN 8 THEN '78'
WHEN 9 THEN '79'
WHEN 10 THEN '80'
WHEN 11 THEN '81'
WHEN 12 THEN '82'
WHEN 13 THEN '83'
WHEN 14 THEN '84'
END
FROM Members m, _MemberProfileLookupValues ml, memHealthInterests mc
WHERE m.memberID = ml.MemberID
AND m.MemberID = mc.MemberID
AND m.Active = 1
AND ml.OptionID &lt;&gt; 12
GO

The problem that i had with this statement is that it Inserted the memberID with all of these field per memberID, instead of looking for where the values is = lets say 9 and insering the values 79 (According to the CASE)


|||

This was the post is started two days ago, wouold someone please be able to help me out.

Just look at my @.Members table and the @.MemberProfileLookupValues

This was the porst that i posted yesterday, i sat thinking about the problem again today, and came up with something that might help me a little more, and maybe unconfuse the situation.

I want to insert all the generated memberID's in the members table into the @.MemberProfileLookupValues table with the AlcoholID's and MemSmokingID's

Hovever the New Profiler accepts the MemberID, OptionID, and ValuesID
Where the old way it was done was basically a pivotted way of doing it, i'm basically just un-pivvotting the table in the new table.

Code Snippet

--Real Code that i actually used.
INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)
SELECT m.MemberID, '12', CASE MC.HealthInterestID
WHEN 1 THEN '71'
WHEN 2 THEN '72'
WHEN 3 THEN '73'
WHEN 4 THEN '74'
WHEN 5 THEN '75'
WHEN 6 THEN '76'
WHEN 7 THEN '77'
WHEN 8 THEN '78'
WHEN 9 THEN '79'
WHEN 10 THEN '80'
WHEN 11 THEN '81'
WHEN 12 THEN '82'
WHEN 13 THEN '83'
WHEN 14 THEN '84'
END
FROM Members m, _MemberProfileLookupValues ml, memHealthInterests mc
WHERE m.memberID = ml.MemberID
AND m.MemberID = mc.MemberID
AND m.Active = 1
AND ml.OptionID &lt;&gt; 12
GO

The problem that i had with this statement is that it Inserted the memberID with all of these field per memberID, instead of looking for where the values is = lets say 9 and insering the values 79 (According to the CASE)

|||

Carel,

I've been hoping (obviously, against hope) that you would see the mistakes inherrent in attempting to shove a EAV data model into a relationation data engine. Here, I'm going to allow someone else to attempt to explain it again. (From: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61024&whichpage=2, Michael Jones:

I think that the query you posted is a perfect illustration of the biggest disadvantage of the Entity/Attribute model, that it saves a little work up front in data modeling by allowing “open ended” insertion of new attributes at the cost of having to program the true data structure into each query. Of course, there are other annoying little problems, like enforcing not null, DRI, domain integrity, default values, check constraints, creating useful indexes, transactional integrity, etc. Basically, it takes all the most useful features of a relational data model, and throws them away.

I have to revise my other non-PC comment: "Encoded in binary, then base64 encoded into text? That’s one of the stupidest thing I've ever seen, but it looks like a stoke of genius compared to using an Entity/Attribute data model!!! What brain-dead morons came up with that!? I know it had to be a committee, because no one could be that stupid all on their own!"

The 'Original Members' table is the 'best' way to store this data. Both attempts of using some form of EAV is a bastardization of the relational database, and will always cause you more grief than it is worth. The task at hand is but one more example.

Using the code you provided (and thank you for the DDL and sample data!!!), it seems that you may be over-complicating the process. I think that it will work for you like this:

Code Snippet

INSERT INTO @.MemberProfileLookupValues
( MemberID,
OptionID,
ValueID
)
SELECT
m.MemberID,
'6',
CASE m.MaritalStatusID
WHEN 1 THEN '7'
WHEN 2 THEN '8'
WHEN 3 THEN '9'
WHEN 4 THEN '10'
ELSE NULL
END
FROM @.Members m

EntryID MemberID OptionID ValueID
-- -- -- --
1 1 6 8
2 2 6 7

Please do yourself a favor and do some research on the issues, problems, and pitfalls related to EAV data and relational databases.

(There are EAV databases available -I don't know how they evaluate...)

|||

Hi Arnie

Thanks for the help with that thread. I read what went on there and i agree with what the guys are talking about. Unfortunately i have been given the task of converting from the old model (Which is right) to the new model i.e. (EAV).

I don't have much say in the matter as the company outsourced the EAV system which was created and actually paid money for it.

When i ran my query to insert the memberID's into the EAV model then it would run through the whole case statement and insert each value per member. for example.

Instead of looking for where the value is 1 and then assigning it value 7.

It would insert values (7, 8, 9, and 10) per memberID for all memberID's. That was my problem. (And it would do it Multiple Times)

Maybe something is wrong, but it looks right to me and it makes sense. (i'm not too concerned about the type of model at present moment) i just want the data to go into the tables right.

Code Snippet

--INSERT memSmokingID Data of Members from Members Table

SET NOCOUNT ON

INSERTINTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

SELECT m.MemberID,'9',CASE M.MemSmokingID

WHEN 1 THEN'59'

WHEN 2 THEN'60'

WHEN 3 THEN'61'

WHEN 4 THEN'62'

END

FROM Members M

INNERJOIN _MemberProfileLookupValues ML ON M.MemberID = ML.MemberID

WHERE M.Active = 1

AND ml.OptionID <> 9

GO

|||

Why do you JOIN to [_MemberProfileLookupValues]?

That JOIN produces a row in the resultset for each row in [_MemberProfileLookupValues] -and I think that you only want one row per [Members] row.

Unless I don't have a complete picture of the data, you would be better off, as in my previous example, leaving the JOIN and WHERE clause out of the query. (I suspose you could still have the [m.Active = 1] filter though...)

|||

As i said in my previous post, stupidity resides EVERYWHERE

Thanks Arnie (AGAIN!!!) he he

makes sense now to me why it would keep on inserting more and more duplicates.

Monday, March 19, 2012

BULK INSERT old BCP format files in SQL 2005

I am not able to BULK INSERT data files in SQL 2005 because it is
complaining about the format of the format description file (.fmt) (it says
something about invalid xml character ...) I am aware of the new XML format
definition and obviously by default SQL assumes that the format file
specified in the BULK INSERT is the new XML one. Everything works fine if I
use command line BCP utility which allows me to specify the format of the
format file. How do I specify it with BULK INSERT statement?
//MishaYou can specify the format file with BULK INSERT statement.
Format description in BOL:
BULK INSERT
[ database_name . [ schema_name ] . | schema_name . ] [ table_name |
view_name ]
FROM 'data_file'
[ WITH
(
[ [ , ] BATCHSIZE = batch_size ]
[ [ , ] CHECK_CONSTRAINTS ]
[ [ , ] CODEPAGE = { 'ACP' | 'OEM' | 'RAW' | 'code_page' } ]
[ [ , ] DATAFILETYPE = { 'char' | 'native'| 'widechar' | 'widenative' } ]
[ [ , ] FIELDTERMINATOR = 'field_terminator' ]
[ [ , ] FIRSTROW =first_row ]
[ [ , ] FIRE_TRIGGERS ]
[ [ , ] FORMATFILE = 'format_file_path' ]
[ [ , ] KEEPIDENTITY ]
[ [ , ] KEEPNULLS ]
[ [ , ] KILOBYTES_PER_BATCH =kilobytes_per_batch ]
[ [ , ] LASTROW = last_row ]
[ [ , ] MAXERRORS = max_errors ]
[ [ , ] ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) ]
[ [ , ] ROWS_PER_BATCH = rows_per_batch ]
[ [ , ] ROWTERMINATOR = 'row_terminator' ]
[ [ , ] TABLOCK ]
[ [ , ] ERRORFILE = 'file_name' ]
)]
Q
"Misha" wrote:
> I am not able to BULK INSERT data files in SQL 2005 because it is
> complaining about the format of the format description file (.fmt) (it says
> something about invalid xml character ...) I am aware of the new XML format
> definition and obviously by default SQL assumes that the format file
> specified in the BULK INSERT is the new XML one. Everything works fine if I
> use command line BCP utility which allows me to specify the format of the
> format file. How do I specify it with BULK INSERT statement?
> //Misha
>
>

BULK INSERT in 2005 does not understand old BCP format file (cretaed in 2000)

I am not able to BULK INSERT data files in SQL 2005 because it is
complaining about the format of the format description file (.fmt) (it says
something about invalid xml character ...) I am aware of the new XML format
definition and obviously by default SQL assumes that the format file
specified in the BULK INSERT is the new XML one. Everything works fine if I
use command line BCP utility which allows me to specify the format of the
format file. How do I specify it with BULK INSERT statement?
//MishaMisha,
Could you please show the first 5 lines of the format file? Maybe seeing it
would give a clue.
RLF
"Misha" <mishka_mishka@.inbox.ru> wrote in message
news:eeqSdL8dIHA.4476@.TK2MSFTNGP06.phx.gbl...
>I am not able to BULK INSERT data files in SQL 2005 because it is
> complaining about the format of the format description file (.fmt) (it
> says
> something about invalid xml character ...) I am aware of the new XML
> format
> definition and obviously by default SQL assumes that the format file
> specified in the BULK INSERT is the new XML one. Everything works fine if
> I
> use command line BCP utility which allows me to specify the format of the
> format file. How do I specify it with BULK INSERT statement?
> //Misha
>|||Here are the first 5 lines of my .fmt file:
--cut here--
8.0
26
1 SQLCHAR 0 4 " " 0 Timestamp ""
2 SQLCHAR 0 8000 " " 1 Company ""
--cut here--
The same lines in HEX:
00000000: 38 2E 30 0D 0A 32 36 0D ? 0A 31 09 53 51 4C 43 48
8.0
26
1 SQLCH
00000010: 41 52 09 30 09 34 09 22 ? 07 22 09 30 09 54 69 6D
AR 0 4 " " 0 Tim
00000020: 65 73 74 61 6D 70 09 22 ? 22 0D 0A 32 09 53 51 4C
estamp ""
2 SQL
00000030: 43 48 41 52 09 30 09 38 ? 30 30 30 09 22 07 22 09
CHAR 0 8000 " "
00000040: 31 09 43 6F 6D 70 61 6E ? 79 09 22 22 0D 0A 33 09
1 Company ""
3
//Misha
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:%23vOhYw8dIHA.3756@.TK2MSFTNGP06.phx.gbl...
> Misha,
> Could you please show the first 5 lines of the format file? Maybe seeing
> it would give a clue.
> RLF
> "Misha" <mishka_mishka@.inbox.ru> wrote in message
> news:eeqSdL8dIHA.4476@.TK2MSFTNGP06.phx.gbl...
>>I am not able to BULK INSERT data files in SQL 2005 because it is
>> complaining about the format of the format description file (.fmt) (it
>> says
>> something about invalid xml character ...) I am aware of the new XML
>> format
>> definition and obviously by default SQL assumes that the format file
>> specified in the BULK INSERT is the new XML one. Everything works fine if
>> I
>> use command line BCP utility which allows me to specify the format of the
>> format file. How do I specify it with BULK INSERT statement?
>> //Misha
>|||Misha,
I really do not know the answer. I also get XML errors on "invalid
character", but when I replace your separator character with a "," it all
works. (I tried saving your .fmt file as both ANSI and UNICODE. I get
different errors, but I still get errors.)
It makes me wonder if the format file, when being read is turned into
internal XML and the XML does not allow your separator character (which is
0x07) to exist.
Can you readily change to another separator character?
FWIW,
RLF
"Misha" <mishka_mishka@.inbox.ru> wrote in message
news:%23VY38aEeIHA.5984@.TK2MSFTNGP06.phx.gbl...
> Here are the first 5 lines of my .fmt file:
> --cut here--
> 8.0
> 26
> 1 SQLCHAR 0 4 " " 0 Timestamp ""
> 2 SQLCHAR 0 8000 " " 1 Company ""
> --cut here--
> The same lines in HEX:
> 00000000: 38 2E 30 0D 0A 32 36 0D ? 0A 31 09 53 51 4C 43 48 8.0
> 26
> 1 SQLCH
> 00000010: 41 52 09 30 09 34 09 22 ? 07 22 09 30 09 54 69 6D AR 0 4 " " 0
> Tim
> 00000020: 65 73 74 61 6D 70 09 22 ? 22 0D 0A 32 09 53 51 4C estamp ""
> 2 SQL
> 00000030: 43 48 41 52 09 30 09 38 ? 30 30 30 09 22 07 22 09 CHAR 0 8000
> " " 00000040: 31 09 43 6F 6D 70 61 6E ? 79 09 22 22 0D 0A 33 09 1 Company
> ""
> 3
> //Misha
> "Russell Fields" <russellfields@.nomail.com> wrote in message
> news:%23vOhYw8dIHA.3756@.TK2MSFTNGP06.phx.gbl...
>> Misha,
>> Could you please show the first 5 lines of the format file? Maybe seeing
>> it would give a clue.
>> RLF
>> "Misha" <mishka_mishka@.inbox.ru> wrote in message
>> news:eeqSdL8dIHA.4476@.TK2MSFTNGP06.phx.gbl...
>>I am not able to BULK INSERT data files in SQL 2005 because it is
>> complaining about the format of the format description file (.fmt) (it
>> says
>> something about invalid xml character ...) I am aware of the new XML
>> format
>> definition and obviously by default SQL assumes that the format file
>> specified in the BULK INSERT is the new XML one. Everything works fine
>> if I
>> use command line BCP utility which allows me to specify the format of
>> the
>> format file. How do I specify it with BULK INSERT statement?
>> //Misha
>>
>|||Thanks a lot for your help Russell,
I have switched the application onto the new XML format file format and it
works fine. Obviously MS has a bug in SQL 2005 with the old fmt files.
//Misha
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:%23%23jgRkJeIHA.288@.TK2MSFTNGP02.phx.gbl...
> Misha,
> I really do not know the answer. I also get XML errors on "invalid
> character", but when I replace your separator character with a "," it all
> works. (I tried saving your .fmt file as both ANSI and UNICODE. I get
> different errors, but I still get errors.)
> It makes me wonder if the format file, when being read is turned into
> internal XML and the XML does not allow your separator character (which is
> 0x07) to exist.
> Can you readily change to another separator character?
> FWIW,
> RLF
>
> "Misha" <mishka_mishka@.inbox.ru> wrote in message
> news:%23VY38aEeIHA.5984@.TK2MSFTNGP06.phx.gbl...
>> Here are the first 5 lines of my .fmt file:
>> --cut here--
>> 8.0
>> 26
>> 1 SQLCHAR 0 4 " " 0 Timestamp ""
>> 2 SQLCHAR 0 8000 " " 1 Company ""
>> --cut here--
>> The same lines in HEX:
>> 00000000: 38 2E 30 0D 0A 32 36 0D ? 0A 31 09 53 51 4C 43 48 8.0
>> 26
>> 1 SQLCH
>> 00000010: 41 52 09 30 09 34 09 22 ? 07 22 09 30 09 54 69 6D AR 0 4 " " 0
>> Tim
>> 00000020: 65 73 74 61 6D 70 09 22 ? 22 0D 0A 32 09 53 51 4C estamp ""
>> 2 SQL
>> 00000030: 43 48 41 52 09 30 09 38 ? 30 30 30 09 22 07 22 09 CHAR 0 8000
>> " " 00000040: 31 09 43 6F 6D 70 61 6E ? 79 09 22 22 0D 0A 33 09 1
>> Company ""
>> 3
>> //Misha
>> "Russell Fields" <russellfields@.nomail.com> wrote in message
>> news:%23vOhYw8dIHA.3756@.TK2MSFTNGP06.phx.gbl...
>> Misha,
>> Could you please show the first 5 lines of the format file? Maybe
>> seeing it would give a clue.
>> RLF
>> "Misha" <mishka_mishka@.inbox.ru> wrote in message
>> news:eeqSdL8dIHA.4476@.TK2MSFTNGP06.phx.gbl...
>>I am not able to BULK INSERT data files in SQL 2005 because it is
>> complaining about the format of the format description file (.fmt) (it
>> says
>> something about invalid xml character ...) I am aware of the new XML
>> format
>> definition and obviously by default SQL assumes that the format file
>> specified in the BULK INSERT is the new XML one. Everything works fine
>> if I
>> use command line BCP utility which allows me to specify the format of
>> the
>> format file. How do I specify it with BULK INSERT statement?
>> //Misha
>>
>>
>

BULK INSERT in 2005 does not understand old BCP format file (cretaed in 2000)

I am not able to BULK INSERT data files in SQL 2005 because it is
complaining about the format of the format description file (.fmt) (it says
something about invalid xml character ...) I am aware of the new XML format
definition and obviously by default SQL assumes that the format file
specified in the BULK INSERT is the new XML one. Everything works fine if I
use command line BCP utility which allows me to specify the format of the
format file. How do I specify it with BULK INSERT statement?
//Misha
Misha,
Could you please show the first 5 lines of the format file? Maybe seeing it
would give a clue.
RLF
"Misha" <mishka_mishka@.inbox.ru> wrote in message
news:eeqSdL8dIHA.4476@.TK2MSFTNGP06.phx.gbl...
>I am not able to BULK INSERT data files in SQL 2005 because it is
> complaining about the format of the format description file (.fmt) (it
> says
> something about invalid xml character ...) I am aware of the new XML
> format
> definition and obviously by default SQL assumes that the format file
> specified in the BULK INSERT is the new XML one. Everything works fine if
> I
> use command line BCP utility which allows me to specify the format of the
> format file. How do I specify it with BULK INSERT statement?
> //Misha
>
|||Here are the first 5 lines of my .fmt file:
--cut here--
8.0
26
1 SQLCHAR 0 4 " " 0 Timestamp ""
2 SQLCHAR 0 8000 " " 1 Company ""
--cut here--
The same lines in HEX:
00000000: 38 2E 30 0D 0A 32 36 0D 0A 31 09 53 51 4C 43 48
8.0
26
1SQLCH
00000010: 41 52 09 30 09 34 09 22 07 22 09 30 09 54 69 6D
AR04" "0Tim
00000020: 65 73 74 61 6D 70 09 22 22 0D 0A 32 09 53 51 4C
estamp""
2SQL
00000030: 43 48 41 52 09 30 09 38 30 30 30 09 22 07 22 09
CHAR08000" "
00000040: 31 09 43 6F 6D 70 61 6E 79 09 22 22 0D 0A 33 09
1Company""
3
//Misha
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:%23vOhYw8dIHA.3756@.TK2MSFTNGP06.phx.gbl...
> Misha,
> Could you please show the first 5 lines of the format file? Maybe seeing
> it would give a clue.
> RLF
> "Misha" <mishka_mishka@.inbox.ru> wrote in message
> news:eeqSdL8dIHA.4476@.TK2MSFTNGP06.phx.gbl...
>
|||Misha,
I really do not know the answer. I also get XML errors on "invalid
character", but when I replace your separator character with a "," it all
works. (I tried saving your .fmt file as both ANSI and UNICODE. I get
different errors, but I still get errors.)
It makes me wonder if the format file, when being read is turned into
internal XML and the XML does not allow your separator character (which is
0x07) to exist.
Can you readily change to another separator character?
FWIW,
RLF
"Misha" <mishka_mishka@.inbox.ru> wrote in message
news:%23VY38aEeIHA.5984@.TK2MSFTNGP06.phx.gbl...
> Here are the first 5 lines of my .fmt file:
> --cut here--
> 8.0
> 26
> 1 SQLCHAR 0 4 " " 0 Timestamp ""
> 2 SQLCHAR 0 8000 " " 1 Company ""
> --cut here--
> The same lines in HEX:
> 00000000: 38 2E 30 0D 0A 32 36 0D 0A 31 09 53 51 4C 43 48 8.0
> 26
> 1 SQLCH
> 00000010: 41 52 09 30 09 34 09 22 07 22 09 30 09 54 69 6D AR 0 4 " " 0
> Tim
> 00000020: 65 73 74 61 6D 70 09 22 22 0D 0A 32 09 53 51 4C estamp ""
> 2 SQL
> 00000030: 43 48 41 52 09 30 09 38 30 30 30 09 22 07 22 09 CHAR 0 8000
> " " 00000040: 31 09 43 6F 6D 70 61 6E 79 09 22 22 0D 0A 33 09 1 Company
> ""
> 3
> //Misha
> "Russell Fields" <russellfields@.nomail.com> wrote in message
> news:%23vOhYw8dIHA.3756@.TK2MSFTNGP06.phx.gbl...
>
|||Thanks a lot for your help Russell,
I have switched the application onto the new XML format file format and it
works fine. Obviously MS has a bug in SQL 2005 with the old fmt files.
//Misha
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:%23%23jgRkJeIHA.288@.TK2MSFTNGP02.phx.gbl...
> Misha,
> I really do not know the answer. I also get XML errors on "invalid
> character", but when I replace your separator character with a "," it all
> works. (I tried saving your .fmt file as both ANSI and UNICODE. I get
> different errors, but I still get errors.)
> It makes me wonder if the format file, when being read is turned into
> internal XML and the XML does not allow your separator character (which is
> 0x07) to exist.
> Can you readily change to another separator character?
> FWIW,
> RLF
>
> "Misha" <mishka_mishka@.inbox.ru> wrote in message
> news:%23VY38aEeIHA.5984@.TK2MSFTNGP06.phx.gbl...
>

Thursday, March 8, 2012

Bulk Insert doubts

Hello Guys,

soon soon, ll have to devellop some procedures to read an ASCII file to supply MS SQL tables. As Ive read some old post, Ive understand that I have to use BULK INSERT , or else, BCP or DTS. Id like to know the diference between this commands and witch of them is more powerful, faster and efficient. If you can give me some implementation tips, I will be very grateful.

thanx allDid you look it up in BOL...

How is the data stored?

anyway...I almost exclusivley use bcp for Production code

BULK INSERT usually for quick data analysis..

and DTS for analysis, if the data is in Excel, Access, whatever...|||DTS is the most flexible, because it can go from more or less automated (using the wizard), to very task oriented (using the painter), to micro-managing the transfer (using VBA).

BCP and BULK INSERT are both tools that expose the current equivalents to the old Bulk Copy API. They are very efficient, but not extremely flexible or friendly.

-PatP|||But what's the most effecient?

EDIT: And do you not think releasing DTS to a production environment is more painful?|||BCP and BULK INSERT are simply differet front ends to the same code. Performancewise the difference is irrelevant.

I live and breathe in a replicated environment. One of our machines does virtually all of our DTS jobs against an "interface" server that has little or no user load.

We use DTS against our OLTP servers, our DW servers, and a number of "friendly" machines that need data. I've never had any real complaints about it.

-PatP|||Well thanx for all replies... Talking about what I have... Ill have 30 ASCII files to load as I told you, and approximatly 91292,42 KB for each... Itll run in production environment, to synchronize the ambient for a BI system... Which comand should I use?

Originally posted by Brett Kaiser
Did you look it up in BOL...

How is the data stored?

anyway...I almost exclusivley use bcp for Production code

BULK INSERT usually for quick data analysis..

and DTS for analysis, if the data is in Excel, Access, whatever...|||I suggest DTS is best and reliable tool to import those ASCII text files to the database. And even you can schedule the same package if its ongoing BI requirement.

As suggested you should follow books online for all the information.
For DTS specifically keep in touch with http://www.sqldts.com.

Tuesday, February 14, 2012

Built-In Administrators disabled! Please help!

We're in a big mess here:
One of our groups has taken it upon themselves to cleanup some of their SQL
servers of old and unwanted logins. The first thing to go on the first
machine was the 'built-in administrators' group. Now, the SQL server is
unreachable. Can't register to another machine, can't make changes, NOTHING
.
Can someone provide some guidance to enabling the account, please?
Also, I wasn't aware that disabling the built-in would cause this problem,
especially since we have alternate accounts that act as db owners and
administrators. is the built-in account somehing we should just put on the
side and leave alone? Thanks!add a login account for the Local System account
using sp_grantlogin [NT Authority\System] and ensure that the login acco
unt
is a member of the sysadmin fixed server role.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"D Lee" <DLee@.discussions.microsoft.com> wrote in message
news:4FC1DBEE-21BE-4B9F-9B99-AA616A5ACB26@.microsoft.com...
> We're in a big mess here:
> One of our groups has taken it upon themselves to cleanup some of their
> SQL
> servers of old and unwanted logins. The first thing to go on the first
> machine was the 'built-in administrators' group. Now, the SQL server is
> unreachable. Can't register to another machine, can't make changes,
> NOTHING.
> Can someone provide some guidance to enabling the account, please?
> Also, I wasn't aware that disabling the built-in would cause this problem,
> especially since we have alternate accounts that act as db owners and
> administrators. is the built-in account somehing we should just put on
> the
> side and leave alone? Thanks!|||hillary's idea sounds right to me. I will add that disabling the local
admins is a great security idea but the genius left out a step.
Create a SQL Server Administrators group in the domain. Add that group to
the local administrators group on the box. Add that group to the SQL Server
and make it a sysadmin. NOW take out the local administrators and you'll be
fine.
BTW: don't forget to add people to the SQL Server Administrators group.
d.
"D Lee" <DLee@.discussions.microsoft.com> wrote in message
news:4FC1DBEE-21BE-4B9F-9B99-AA616A5ACB26@.microsoft.com...
> We're in a big mess here:
> One of our groups has taken it upon themselves to cleanup some of their
SQL
> servers of old and unwanted logins. The first thing to go on the first
> machine was the 'built-in administrators' group. Now, the SQL server is
> unreachable. Can't register to another machine, can't make changes,
NOTHING.
> Can someone provide some guidance to enabling the account, please?
> Also, I wasn't aware that disabling the built-in would cause this problem,
> especially since we have alternate accounts that act as db owners and
> administrators. is the built-in account somehing we should just put on
the
> side and leave alone? Thanks!

Built-In Administrators disabled! Please help!

We're in a big mess here:
One of our groups has taken it upon themselves to cleanup some of their SQL
servers of old and unwanted logins. The first thing to go on the first
machine was the 'built-in administrators' group. Now, the SQL server is
unreachable. Can't register to another machine, can't make changes, NOTHING.
Can someone provide some guidance to enabling the account, please?
Also, I wasn't aware that disabling the built-in would cause this problem,
especially since we have alternate accounts that act as db owners and
administrators. is the built-in account somehing we should just put on the
side and leave alone? Thanks!
add a login account for the Local System account
using sp_grantlogin [NT Authority\System] and ensure that the login account
is a member of the sysadmin fixed server role.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"D Lee" <DLee@.discussions.microsoft.com> wrote in message
news:4FC1DBEE-21BE-4B9F-9B99-AA616A5ACB26@.microsoft.com...
> We're in a big mess here:
> One of our groups has taken it upon themselves to cleanup some of their
> SQL
> servers of old and unwanted logins. The first thing to go on the first
> machine was the 'built-in administrators' group. Now, the SQL server is
> unreachable. Can't register to another machine, can't make changes,
> NOTHING.
> Can someone provide some guidance to enabling the account, please?
> Also, I wasn't aware that disabling the built-in would cause this problem,
> especially since we have alternate accounts that act as db owners and
> administrators. is the built-in account somehing we should just put on
> the
> side and leave alone? Thanks!
|||hillary's idea sounds right to me. I will add that disabling the local
admins is a great security idea but the genius left out a step.
Create a SQL Server Administrators group in the domain. Add that group to
the local administrators group on the box. Add that group to the SQL Server
and make it a sysadmin. NOW take out the local administrators and you'll be
fine.
BTW: don't forget to add people to the SQL Server Administrators group.
d.
"D Lee" <DLee@.discussions.microsoft.com> wrote in message
news:4FC1DBEE-21BE-4B9F-9B99-AA616A5ACB26@.microsoft.com...
> We're in a big mess here:
> One of our groups has taken it upon themselves to cleanup some of their
SQL
> servers of old and unwanted logins. The first thing to go on the first
> machine was the 'built-in administrators' group. Now, the SQL server is
> unreachable. Can't register to another machine, can't make changes,
NOTHING.
> Can someone provide some guidance to enabling the account, please?
> Also, I wasn't aware that disabling the built-in would cause this problem,
> especially since we have alternate accounts that act as db owners and
> administrators. is the built-in account somehing we should just put on
the
> side and leave alone? Thanks!

Built-In Administrators disabled! Please help!

We're in a big mess here:
One of our groups has taken it upon themselves to cleanup some of their SQL
servers of old and unwanted logins. The first thing to go on the first
machine was the 'built-in administrators' group. Now, the SQL server is
unreachable. Can't register to another machine, can't make changes, NOTHING.
Can someone provide some guidance to enabling the account, please?
Also, I wasn't aware that disabling the built-in would cause this problem,
especially since we have alternate accounts that act as db owners and
administrators. is the built-in account somehing we should just put on the
side and leave alone? Thanks!add a login account for the Local System account
using sp_grantlogin [NT Authority\System] and ensure that the login account
is a member of the sysadmin fixed server role.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"D Lee" <DLee@.discussions.microsoft.com> wrote in message
news:4FC1DBEE-21BE-4B9F-9B99-AA616A5ACB26@.microsoft.com...
> We're in a big mess here:
> One of our groups has taken it upon themselves to cleanup some of their
> SQL
> servers of old and unwanted logins. The first thing to go on the first
> machine was the 'built-in administrators' group. Now, the SQL server is
> unreachable. Can't register to another machine, can't make changes,
> NOTHING.
> Can someone provide some guidance to enabling the account, please?
> Also, I wasn't aware that disabling the built-in would cause this problem,
> especially since we have alternate accounts that act as db owners and
> administrators. is the built-in account somehing we should just put on
> the
> side and leave alone? Thanks!|||hillary's idea sounds right to me. I will add that disabling the local
admins is a great security idea but the genius left out a step.
Create a SQL Server Administrators group in the domain. Add that group to
the local administrators group on the box. Add that group to the SQL Server
and make it a sysadmin. NOW take out the local administrators and you'll be
fine.
BTW: don't forget to add people to the SQL Server Administrators group.
d.
"D Lee" <DLee@.discussions.microsoft.com> wrote in message
news:4FC1DBEE-21BE-4B9F-9B99-AA616A5ACB26@.microsoft.com...
> We're in a big mess here:
> One of our groups has taken it upon themselves to cleanup some of their
SQL
> servers of old and unwanted logins. The first thing to go on the first
> machine was the 'built-in administrators' group. Now, the SQL server is
> unreachable. Can't register to another machine, can't make changes,
NOTHING.
> Can someone provide some guidance to enabling the account, please?
> Also, I wasn't aware that disabling the built-in would cause this problem,
> especially since we have alternate accounts that act as db owners and
> administrators. is the built-in account somehing we should just put on
the
> side and leave alone? Thanks!