Lord Kelvan (the_iddiot@hotmail.com) writes:
[quoted text, click to view] > i have a trigger a nice trigger it is for horizontal partitioning it
> is 700 lines (really big database) so I am not posting it not that it
> is necessary the only valuable information it is acts on when a record
> is updated and a certain value is added to a column in the database
> the trigger then acts and horizontal partitions that record sticking
> it in a second part of the database basically a mirror for old data
> that the "boss" doesn't want delete ... ever.
>
> of course I convinced the boss that the computer is not an infinite
> storage place and now the "boss" (and I am using this term lightly at
> this point) wants to be able to extract all information from the
> database on a certain record set (this set is a project and all data
> related to that project) and stick it in a file so she can then burn
> it to a cd ... or dvd depending on how big it is.
If the data size is not bigger than it can fit on a DVD, why even bother?
Or you are running MSDE or SQL Express and have keep within the database
size limits?
[quoted text, click to view] > But wait there is more the "boss" wants to be able to import it back
> into the system at any time if the data on that project suddenly becomes
> relevant for god knows what reason.
>
> I need a bit of sql that I can add to that trigger that will write all
> that data to a file with insert statements and what not that are
> related to that projectid. that or I add it somewhere else the thing
> is i need to either put it in a trigger where I can update a value
> like I am doing for the horizontal partitioning trigger or give the
> sql to the interface guy and tell him to add it to the interface to be
> processed at the click of a button on the interface.
So the idea is to archive the data as INSERT statements? First of all,
don't to this from the trigger. A trigger is meant for operation that
must be carried out as part of the transaction defined by the statement
that fired the trigger, and this obviously isn't. As I understand it,
a set of data is marked for archiving. Then a process at some later
point could perform the archiving operation.
That process could run from SQL Server Agent or be started manually.
Whatever, it should not run from T-SQL, because T-SQL is not meant
for writing to files.
As for which form to archive the data, this requires some consideration.
You appear to be considering INSERT statements. But what if the schema
has changed when you need the data in two years? Maybe it would be better
to move the data to a second database with table and all, and the you
can just write that database file to the CD or DVD. Just keep in mind
that if you need it in 10 years from now, the version of SQL Server you
have then, may not support attaching a database of the version you have now.
How big is the total database? Maybe it the simplest is to take a full
backup of the database, send the backup to the archive and the purge the
rows from the database. Of course the same caveat about what may happen
in 2017 still applies.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at