Showing posts with label dts. Show all posts
Showing posts with label dts. Show all posts

Sunday, March 25, 2012

Creating a table with a dual primary key

This question may be a little complicated.

I am building a DTS Package that is moving data from our webstore (written in house) to a Warehouse Management System(WMS - Turnkey) and I've encountered a problem. both pieces of software have an orders table and an Ordered_Items table, related by the order_ID (makes sense so far). Here is the problem. The primary key on the webstore's Ordered_Items table is a single column (basically an Identity variable), while the primary key on the WMS's Ordered_Items table is a dual column primary key, between the Order_ID and the Order_LineID, so the data should be stored like:

OrderID Order_LineID
1 1
2 1
2 2
2 3
3 1
3 2
4 1

Get the Idea? So I have to create this new Order_LineID column. How can I accomplish this with a SQL statement?

Thanks!!!!!Does it matter that the destination needs to start at 1 and be sequential? If not, just use the Identity value. Probably too simple.

If you do it in a cursor, you could use a counter and move each record one at a time and use your counter to create the line number.

You could create the line number field in your source and pre-populate it with a process to loop through and assign the line numbers just prior to dumping it to the destination.

Doing it within one SQL statement to move it from one to the other might be impossible.|||Yes, you can create primary key that consists of two columns, or composite primary key.
It is not possible to create dual promary key in SQL server. You may create multiple uniqe index/constraints. But for one talbe, there is only one primary key.|||It is not quite clear what you exactly want to do.

Do you want to add a new column for an existing table as a primary key or is it a whole new table?|||I think we are on the right track (sort of).

I my example, the Order ID's are already assigned (they basically use an Identity Key).

What I need is some sort of query (or activeX script) that will loop through each record, and assign the Order_Line_ID (By the way, I don't care how many SQL statements this takes, as long as it works).

I am querying the Order_Line table, and sorting it by the Order#, so the table will look like this at first:

LineID-Identity | Order#
1 | 12345
2 | 12345
3 | 12345
4 | 12346
5 | 12347
6 | 12347
7 | 12348

The idea is, an order may have multiple lines (you've probably ordered more than one item at a time from some site online)

The counter needs to start over at 1 when it comes to a new order. For example, if the first three records in the Order_Line table are from Order# 12345, the first three rows would be numbered 1, 2 and 3, respectively (that should make sense). Now the tricky part: If the next Order # is 12346, the counter would start at 1 again, like this.

LineID-Identity | Order# | OrderLine#
1 | 12345 | 1
2 | 12345 | 2
3 | 12345 | 3
4 | 12346 | 1
5 | 12347 | 1
6 | 12347 | 2
7 | 12348 | 1

As you can see, this is a new column, so no data is being removed. How do you do this?|||Within SQL, use a cursor and loop through a sorted list of the line items. Use a "current" and "previous" variable to hold the order ID and a counter to hold the new line number. Create the field (null at first), loop through the cursor and using the logic of comparing the last order ID to the current one, assign the line number from the counter, increment the counter, etc. Look up the cursor options you'll need to use to make the cursor editable.

Wednesday, March 21, 2012

Creating a SSIS package

HI All,

can any body give steps to import data from one sqldb to another through ssis package, i was comfotable with dts but ssis is a lil bit confusing.....

thnx

regards

Start with the Wizard. Use it to build your first package, then save it and open it up in the designer, and you have your first sample package to learn from.

You actually want the Data Flow task for this, but why not let the Wizard show you for now.

You may find it useful to give these a try to help get you familiar with SSIS

Integration Services Tutorials
(http://msdn2.microsoft.com/en-us/library/0fc6e3a7-1c12-444a-b1ef-ead622f805d2.aspx)

Thursday, March 8, 2012

Creating a job with many steps including DTS

Hi,
(using Windows 2000 Server/SQL2K Ent Ed SP3a)
I am looking to create a job with a number of steps inside it. I need
the job to run on a sunday afternoon when our OLTP system is at our
quietest in terms of user connections and throughput. The job purpose
is to copy data (24,000,000 rows) from one table to another on the same
database, via a DTS package. I then need to rename the old table,
removing the triggers and views on it, then rename the new table, and
add the relevent objects (including indexs and constraints) then add
the permissions on it.
These are the steps:
1) Set restricted user mode on database
2) Run the DTS package
3) Remove triggers and views on old table
4) Rename old table
5) Rename new table
6) Add indexs and constraints to new table
7) Add triggers/views to new table
8) Set permissions to new table
9) Set multi user mode on database
My question would be does the above seem logical, or would there be a
better way of performing this process? Do I need the DTS package, would
a INSERT INTO be better, or could I use a DTS package for the entire
process?
Thanks and rgds,
qhHi
INSERT..SELECT may be a better option.
You may want to try something like the following to avoid the rename steps:
Create Archive Table
Insert Into Archive Table
Delete Archived Data from Live Table
ReIndex Live Table
You may also be able to do this in smaller increments each night instead of
once a w.
John
"Scott" wrote:

> Hi,
> (using Windows 2000 Server/SQL2K Ent Ed SP3a)
> I am looking to create a job with a number of steps inside it. I need
> the job to run on a sunday afternoon when our OLTP system is at our
> quietest in terms of user connections and throughput. The job purpose
> is to copy data (24,000,000 rows) from one table to another on the same
> database, via a DTS package. I then need to rename the old table,
> removing the triggers and views on it, then rename the new table, and
> add the relevent objects (including indexs and constraints) then add
> the permissions on it.
> These are the steps:
> 1) Set restricted user mode on database
> 2) Run the DTS package
> 3) Remove triggers and views on old table
> 4) Rename old table
> 5) Rename new table
> 6) Add indexs and constraints to new table
> 7) Add triggers/views to new table
> 8) Set permissions to new table
> 9) Set multi user mode on database
>
> My question would be does the above seem logical, or would there be a
> better way of performing this process? Do I need the DTS package, would
> a INSERT INTO be better, or could I use a DTS package for the entire
> process?
> Thanks and rgds,
> qh
>

Wednesday, March 7, 2012

Creating a DTS package programaticaly

Hi,
I want to create a DTS package programatically (preferably in
C#.net),which will copy all my tables from a oracle database to my
sql-server database.
Can anybody help me doing this?
Thanks
PatnayakBOL documents all of the DTS API:
http://msdn.microsoft.com/library/e...spapps_21rn.asp

Assuming you are using SQL2000 there's an easy way to familiarise yourself
with the basics of DTS programming. Create a sample DTS package (either
using the Wizard or the Designer), open it up in the Designer and choose
Package/Save As... from the menu. Select "Visual Basic File" from the
Location dropdown and specify a file name. This will generate the Visual
Basic code to create and execute your package. You can then dissect, edit
and extend the code as required.

Inevitably there will be some work involved if you want to move the
generated code to C# but the example of how to manipulate the DTS objects
should give you a helpful start.

--
David Portas
----
Please reply only to the newsgroup
--|||To add to David's response, you can find a cookbook and examples for SQL
Server 2000 DTS with .NET at http://www.sqldev.net/dts/DotNETCookBook.htm.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Pattnayak" <dpatnayak@.hotmail.com> wrote in message
news:a57a07c8.0401010301.3d175545@.posting.google.c om...
> Hi,
> I want to create a DTS package programatically (preferably in
> C#.net),which will copy all my tables from a oracle database to my
> sql-server database.
> Can anybody help me doing this?
> Thanks
> Patnayak

Creating a DTS package from a BAS file thru VB

Hello. ok, if I open a DTS package, and save it as a VB
BAS file, make some alterations to the BAS file, how do I
re-create the DTS package from that updated BAS file? Is
there any short sample code to do this that someone could
point me to? I'm not a VB coder, so just need a shell of
the VB code to run. THanks, BruceThe generated VB code will contain code to either execute or save the
package. The initial code will have the SaveToSqlServer line commented out.
You can remove the comment, specify the correct 'sa' password (and server or
other security credentials), comment out the Execute line and then run the
program. Code snippet example below. Note that you'll need to first delete
the package if you want to save it under the same name to the original
server.
You can find more information on the SaveToSQLServer method in the Books
Online.
'--
' Save or execute package
'--
goPackage.SaveToSQLServer "(local)", "sa", "mypassword"
'goPackage.Execute
Hope this helps.
Dan Guzman
SQL Server MVP
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:abc901c488a9$972e48e0$a501280a@.phx.gbl...
> Hello. ok, if I open a DTS package, and save it as a VB
> BAS file, make some alterations to the BAS file, how do I
> re-create the DTS package from that updated BAS file? Is
> there any short sample code to do this that someone could
> point me to? I'm not a VB coder, so just need a shell of
> the VB code to run. THanks, Bruce|||You da MAN!! actually the DAN, but.........
THanks, I'll try it out Monday... Bruce

>--Original Message--
>The generated VB code will contain code to either
execute or save the
>package. The initial code will have the SaveToSqlServer
line commented out.
>You can remove the comment, specify the correct 'sa'
password (and server or
>other security credentials), comment out the Execute
line and then run the
>program. Code snippet example below. Note that you'll
need to first delete
>the package if you want to save it under the same name
to the original
>server.
>You can find more information on the SaveToSQLServer
method in the Books
>Online.
>'--
>' Save or execute package
>'--
>goPackage.SaveToSQLServer "(local)", "sa", "mypassword"
>'goPackage.Execute
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
>news:abc901c488a9$972e48e0$a501280a@.phx.gbl...
VB[vbcol=seagreen]
do I[vbcol=seagreen]
Is[vbcol=seagreen]
could[vbcol=seagreen]
of[vbcol=seagreen]
>
>.
>

Creating a DTS package from a BAS file thru VB

Hello. ok, if I open a DTS package, and save it as a VB
BAS file, make some alterations to the BAS file, how do I
re-create the DTS package from that updated BAS file? Is
there any short sample code to do this that someone could
point me to? I'm not a VB coder, so just need a shell of
the VB code to run. THanks, Bruce
The generated VB code will contain code to either execute or save the
package. The initial code will have the SaveToSqlServer line commented out.
You can remove the comment, specify the correct 'sa' password (and server or
other security credentials), comment out the Execute line and then run the
program. Code snippet example below. Note that you'll need to first delete
the package if you want to save it under the same name to the original
server.
You can find more information on the SaveToSQLServer method in the Books
Online.
'--
' Save or execute package
'--
goPackage.SaveToSQLServer "(local)", "sa", "mypassword"
'goPackage.Execute
Hope this helps.
Dan Guzman
SQL Server MVP
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:abc901c488a9$972e48e0$a501280a@.phx.gbl...
> Hello. ok, if I open a DTS package, and save it as a VB
> BAS file, make some alterations to the BAS file, how do I
> re-create the DTS package from that updated BAS file? Is
> there any short sample code to do this that someone could
> point me to? I'm not a VB coder, so just need a shell of
> the VB code to run. THanks, Bruce
|||You da MAN!! actually the DAN, but.........
THanks, I'll try it out Monday... Bruce

>--Original Message--
>The generated VB code will contain code to either
execute or save the
>package. The initial code will have the SaveToSqlServer
line commented out.
>You can remove the comment, specify the correct 'sa'
password (and server or
>other security credentials), comment out the Execute
line and then run the
>program. Code snippet example below. Note that you'll
need to first delete
>the package if you want to save it under the same name
to the original
>server.
>You can find more information on the SaveToSQLServer
method in the Books[vbcol=seagreen]
>Online.
>'--
>' Save or execute package
>'--
>goPackage.SaveToSQLServer "(local)", "sa", "mypassword"
>'goPackage.Execute
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
>news:abc901c488a9$972e48e0$a501280a@.phx.gbl...
VB[vbcol=seagreen]
do I[vbcol=seagreen]
Is[vbcol=seagreen]
could[vbcol=seagreen]
of
>
>.
>

Creating a DTS package from a BAS file thru VB

Hello. ok, if I open a DTS package, and save it as a VB
BAS file, make some alterations to the BAS file, how do I
re-create the DTS package from that updated BAS file? Is
there any short sample code to do this that someone could
point me to? I'm not a VB coder, so just need a shell of
the VB code to run. THanks, BruceThe generated VB code will contain code to either execute or save the
package. The initial code will have the SaveToSqlServer line commented out.
You can remove the comment, specify the correct 'sa' password (and server or
other security credentials), comment out the Execute line and then run the
program. Code snippet example below. Note that you'll need to first delete
the package if you want to save it under the same name to the original
server.
You can find more information on the SaveToSQLServer method in the Books
Online.
'--
' Save or execute package
'--
goPackage.SaveToSQLServer "(local)", "sa", "mypassword"
'goPackage.Execute
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:abc901c488a9$972e48e0$a501280a@.phx.gbl...
> Hello. ok, if I open a DTS package, and save it as a VB
> BAS file, make some alterations to the BAS file, how do I
> re-create the DTS package from that updated BAS file? Is
> there any short sample code to do this that someone could
> point me to? I'm not a VB coder, so just need a shell of
> the VB code to run. THanks, Bruce|||You da MAN!! actually the DAN, but.........
THanks, I'll try it out Monday... Bruce
>--Original Message--
>The generated VB code will contain code to either
execute or save the
>package. The initial code will have the SaveToSqlServer
line commented out.
>You can remove the comment, specify the correct 'sa'
password (and server or
>other security credentials), comment out the Execute
line and then run the
>program. Code snippet example below. Note that you'll
need to first delete
>the package if you want to save it under the same name
to the original
>server.
>You can find more information on the SaveToSQLServer
method in the Books
>Online.
>'--
>' Save or execute package
>'--
>goPackage.SaveToSQLServer "(local)", "sa", "mypassword"
>'goPackage.Execute
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
>news:abc901c488a9$972e48e0$a501280a@.phx.gbl...
>> Hello. ok, if I open a DTS package, and save it as a
VB
>> BAS file, make some alterations to the BAS file, how
do I
>> re-create the DTS package from that updated BAS file?
Is
>> there any short sample code to do this that someone
could
>> point me to? I'm not a VB coder, so just need a shell
of
>> the VB code to run. THanks, Bruce
>
>.
>

Creating a DTS package

I've created a DTS package and now I need to distribute it to
different servers.

I've been looking for a way to automatically/programatically create a
DTS package, but have not found anything definite.

From the DTS package itself, I see where I can save the dts package as
a structured file, with the name XXXXX.dts. Once I have that DTS
file, how dow I turn it back into a dts package in Enterprise manager?
I don't want to have to manually create the package for 300+
servers...

Thanks,
JenniferYou can load a DTS structured storage file from EM by right-clicking on
the Data Transformation Services folder and selecting Open Package. You
can then select Package --> Save As in order to save it locally.

This can be a bit tedious if you have a lot of servers. The VBScript
example below will load your DTS structured storage file and save it to
multiple servers using a trusted connection. See the Books Online for
details.

Dim DtsPackage
Set DtsPackage = CreateObject("DTS.Package2")
DtsPackage.LoadFromStorageFile "C:\MyDtsPackages\MyDtsPackage.dts", ""
DtsPackage.SaveToSqlServer "MyServer1", , , 256
DtsPackage.SaveToSqlServer "MyServer2", , , 256
DtsPackage.SaveToSqlServer "MyServer3", , , 256

Note that you can execute a DTS package directly from a structured
storage file using DTSRUN. If your servers have access to a shared
network location, you could execute the package with a UNC path rather
than saving the package locally on each server.

--
Hope this helps.

Dan Guzman
SQL Server MVP

--------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index...epartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--------

"Jennifer" <jennifer1970@.hotmail.com> wrote in message
news:3358f49d.0311041237.15641d35@.posting.google.c om...
> I've created a DTS package and now I need to distribute it to
> different servers.
> I've been looking for a way to automatically/programatically create a
> DTS package, but have not found anything definite.
> From the DTS package itself, I see where I can save the dts package as
> a structured file, with the name XXXXX.dts. Once I have that DTS
> file, how dow I turn it back into a dts package in Enterprise manager?
> I don't want to have to manually create the package for 300+
> servers...
> Thanks,
> Jennifer

Friday, February 24, 2012

Creating a Connection to Database that Does Not Yet Exist

Hello All!
I am in the process of developing a DTS package. My
package will behave as follows:
1. Backup my live database.
2. Using the backup from Step 1., the backup will be
restored using a DIFFERENT name (NewDatabase).
3. Manipulate NewDatabase database.
How can I create a connection in my DTS Package when, at
the time I am creating the package, the NewDatabase
database does not exist? Do I have to use Disconnected
Edits? If so, how? Or, do I use Microsoft Data Link?
If so, how? Or, do I use something else. (As you can
tell from my questions, I am not an expert at this :-)
Any suggestions are greatly appreciated!!You should be able to connect to the master database to do what you need to
do initially.
Ray Higdon MCSE, MCDBA, CCNA
--
"ERR" <anonymous@.discussions.microsoft.com> wrote in message
news:ef7b01c3f1b0$3f8eff20$a301280a@.phx.gbl...
> Hello All!
> I am in the process of developing a DTS package. My
> package will behave as follows:
> 1. Backup my live database.
> 2. Using the backup from Step 1., the backup will be
> restored using a DIFFERENT name (NewDatabase).
> 3. Manipulate NewDatabase database.
> How can I create a connection in my DTS Package when, at
> the time I am creating the package, the NewDatabase
> database does not exist? Do I have to use Disconnected
> Edits? If so, how? Or, do I use Microsoft Data Link?
> If so, how? Or, do I use something else. (As you can
> tell from my questions, I am not an expert at this :-)
> Any suggestions are greatly appreciated!!|||I forgot to mention that I do have an initial connection,
the one to the original database. However, I need my DTS
package to create a connection to the NewDatabase
database once the task of restoring with a new name is
complete.
Thanks in advance!

>--Original Message--
>You should be able to connect to the master database to
do what you need to
>do initially.
>--
>Ray Higdon MCSE, MCDBA, CCNA
>--
>"ERR" <anonymous@.discussions.microsoft.com> wrote in
message
>news:ef7b01c3f1b0$3f8eff20$a301280a@.phx.gbl...
at
>
>.
>|||To do what? If it's only to run a sql script you can use workflow and
connect to the master database and then do the "use yournewdb" command after
you have created it
Ray Higdon MCSE, MCDBA, CCNA
--
"ERR" <anonymous@.discussions.microsoft.com> wrote in message
news:f43101c3f22e$9ff978d0$a301280a@.phx.gbl...
> I forgot to mention that I do have an initial connection,
> the one to the original database. However, I need my DTS
> package to create a connection to the NewDatabase
> database once the task of restoring with a new name is
> complete.
> Thanks in advance!
>
> do what you need to
> message
> at|||what you need to do as per Ray's suggestion is to create the dts package and
set it to connect to master, then create a dynamic task properties and a
global variable <dbname> to change the value of catalog property in
Disconnect Edit DE at run time.
then when you execute the dts package need to execute with the /A switch to
pass the <db> variable which u proide at run time see example below
dtsrun /S <servername> /E /N<packagename> /A <db>:8=newdatabase
this way u can connect to a database at runtime.
--
Olu Adedeji
"Ray Higdon" <sqlhigdon@.nospam.yahoo.com> wrote in message
news:eR5zJ8y8DHA.3880@.tk2msftngp13.phx.gbl...
> To do what? If it's only to run a sql script you can use workflow and
> connect to the master database and then do the "use yournewdb" command
after
> you have created it
> --
> Ray Higdon MCSE, MCDBA, CCNA
> --
> "ERR" <anonymous@.discussions.microsoft.com> wrote in message
> news:f43101c3f22e$9ff978d0$a301280a@.phx.gbl...
>