How Should I Name My History Tables ?

Sep 22, 2006

Hi,

I want to backup an important table every week in creating some history tables.

I would like to create a Dts job or script to create every week a table with the day and month in its name. ( like : [important_table_09-07] , [important_table_09-14],... )



Any idea ?



Thanks.

View 7 Replies


ADVERTISEMENT

How Can I Create A History Of Tables?

May 31, 2006

I have to create a history of tables. Therefore I must know the previous structure of the table. I have to document the changes of the structures of the tables.
Is there a solution for the version 2000?

View 2 Replies View Related

History Tables: Always Subtables?

Mar 5, 2008

When creating history tables that are appended to whenever a record isupdated, should one append the corresponding child table records to theirhistory tables at the same time (so as to have a complete set for eachedit); or should one append the child tables only when those particulartables are edited? I have been doing the latter, but I thought I'd ask forothers' opinions.Thanks!Neil

View 1 Replies View Related

Regarding History Tables In Replication...

Feb 1, 2007

Hi,

                             How frequently will the history tables get deleted in Merge Replication and Transactional Replication with updatable subscriptions??

                            When transactional replication with updatable subscriptions is running in the continuous mode, will the history tables get deleted frequently??

Parameters :

Version : SQL Server 2005 SP1

Mode : Continuous running mode

Subscription type : Pull (for transactional)

Regards,

Swapna.B.

View 1 Replies View Related

Queries In Productions AND History Tables

Jun 18, 2004

I've got a large and growing database in SQL Server 7.0. I'd like to utilize a monthly stored procedure that will search various tables for records that are older than 3 months and copy this data out to corresponding history tables. Typically, most production queries are run only on the new data, but occasionally (like at year-end, for example), we will need to run some queries on data extending back 12 months -- that is, on data in the production tables AND in the history tables. Notwithstanding the fact that I've never done stored procedures*, I would like to know if it is possible to run a query that can search for data in both production and history tables at the same time. I know this sounds like a stupid question, but I read somewhere that doing this qould require some kind of Joining function that is complex...?

Thanks,
Whill96205

* Also, any good resources I could use for developing stored procedures?

View 4 Replies View Related

Auto Create History Tables And Triggers

May 30, 2007

For my company, we have made it a standard to create history tables and triggers for the majority of our production tables. I recently grew tired of consistently spending the time needed to create these tables and triggers so I invested some time in creating a script that would auto generate these.

We recently launched a project which required nearly 100 history tables & triggers to be created. This would have normally taken a good day or two to complete. However, with this script it took a near 10 seconds. Here are some details about the script.

The code below creates a stored procedure that receives two input parameters (@TableName & @CreateTrigger) and performs the following actions:

1) Queries system tables to retrieve table schema for @TableName parameter

2) Creates a History table ("History_" + @TableName) to mimic the original table, plus includes additional history columns.

3) If @CreateTrigger = 'Y' then it creates an Update/Delete trigger on the @TableName table, which is used to populate the History table.


/************************************************************************************************************
Created By: Bryan Massey
Created On: 3/11/2007
Comments: Stored proc performs the following actions:
1) Queries system tables to retrieve table schema for @TableName parameter
2) Creates a History table ("History_" + @TableName) to mimic the original table, plus include
additional history columns.
3) If @CreateTrigger = 'Y' then it creates an Update/Delete trigger on the @TableName table,
which is used to populate the History table.
******************************************* MODIFICATIONS **************************************************
MM/DD/YYYY - Modified By - Description of Changes
************************************************************************************************************/
CREATE PROCEDURE DBO.History_Bat_AutoGenerateHistoryTableAndTrigger
@TableName VARCHAR(200),
@CreateTrigger CHAR(1) = 'Y' -- optional parameter; defaults to "Y"
AS


DECLARE @SQLTable VARCHAR(8000), @SQLTrigger VARCHAR(8000), @FieldList VARCHAR(6000), @FirstField VARCHAR(200)
DECLARE @TAB CHAR(1), @CRLF CHAR(1), @SQL VARCHAR(1000), @Date VARCHAR(12)

SET @TAB = CHAR(9)
SET @CRLF = CHAR(13) + CHAR(10)
SET @Date = CONVERT(VARCHAR(12), GETDATE(), 101)
SET @FieldList = ''
SET @SQLTable = ''


DECLARE @TableDescr VARCHAR(500), @FieldName VARCHAR(100), @DataType VARCHAR(50)
DECLARE @FieldLength VARCHAR(10), @Precision VARCHAR(10), @Scale VARCHAR(10), @FieldDescr VARCHAR(500), @AllowNulls VARCHAR(1)

DECLARE CurHistoryTable CURSOR FOR

-- query system tables to get table schema
SELECT CONVERT(VARCHAR(500), SP2.value) AS TableDescription,
CONVERT(VARCHAR(100), SC.Name) AS FieldName, CONVERT(VARCHAR(50), ST.Name) AS DataType,
CONVERT(VARCHAR(10),SC.length) AS FieldLength, CONVERT(VARCHAR(10), SC.XPrec) AS FieldPrecision,
CONVERT(VARCHAR(10), SC.XScale) AS FieldScale,
CASE SC.IsNullable WHEN 1 THEN 'Y' ELSE 'N' END AS AllowNulls
FROM SysObjects SO
INNER JOIN SysColumns SC ON SO.ID = SC.ID
INNER JOIN SysTypes ST ON SC.xtype = ST.xtype
LEFT OUTER JOIN SysProperties SP ON SC.ID = SP.ID AND SC.ColID = SP.SmallID
LEFT OUTER JOIN SysProperties SP2 ON SC.ID = SP2.ID AND SP2.SmallID = 0
WHERE SO.xtype = 'u' AND SO.Name = @TableName
ORDER BY SO.[name], SC.ColOrder

OPEN CurHistoryTable

FETCH NEXT FROM CurHistoryTable INTO @TableDescr, @FieldName, @DataType,
@FieldLength, @Precision, @Scale, @AllowNulls

WHILE @@FETCH_STATUS = 0
BEGIN

-- create list of table columns
IF LEN(@FieldList) = 0
BEGIN
SET @FieldList = @FieldName
SET @FirstField = @FieldName
END
ELSE
BEGIN
SET @FieldList = @FieldList + ', ' + @FieldName
END


IF LEN(@SQLTable) = 0
BEGIN
SET @SQLTable = 'CREATE TABLE [DBO].[History_' + @TableName + '] (' + @CRLF
SET @SQLTable = @SQLTable + @TAB + '[History' + @FieldName + '] [INT] IDENTITY(1,1) NOT NULL,' + @CRLF
END


SET @SQLTable = @SQLTable + @TAB + '[' + @FieldName + '] ' + '[' + @DataType + ']'

IF UPPER(@DataType) IN ('CHAR', 'VARCHAR', 'NCHAR', 'NVARCHAR', 'BINARY')
BEGIN
SET @SQLTable = @SQLTable + '(' + @FieldLength + ')'
END
ELSE IF UPPER(@DataType) IN ('DECIMAL', 'NUMERIC')
BEGIN
SET @SQLTable = @SQLTable + '(' + @Precision + ', ' + @Scale + ')'
END


IF @AllowNulls = 'Y'
BEGIN
SET @SQLTable = @SQLTable + ' NULL'
END
ELSE
BEGIN
SET @SQLTable = @SQLTable + ' NOT NULL'
END

SET @SQLTable = @SQLTable + ',' + @CRLF


FETCH NEXT FROM CurHistoryTable INTO @TableDescr, @FieldName, @DataType,
@FieldLength, @Precision, @Scale, @AllowNulls
END

CLOSE CurHistoryTable
DEALLOCATE CurHistoryTable

-- finish history table script with standard history columns
SET @SQLTable = @SQLTable + @TAB + '[HistoryCreatedOn] [DATETIME] NULL,' + @CRLF
SET @SQLTable = @SQLTable + @TAB + '[HistoryCreatedByUserID] [SMALLINT] NULL,' + @CRLF

SET @SQLTable = @SQLTable + @TAB + '[HistoryCreatedByUserName] [VARCHAR](30) NULL,' + @CRLF
SET @SQLTable = @SQLTable + @TAB + '[HistoryAction] [CHAR](1) NOT NULL' + @CRLF
SET @SQLTable = @SQLTable + ' )'


PRINT @SQLTable

-- execute sql script to create history table
EXEC(@SQLTable)

IF @@ERROR <> 0
BEGIN
PRINT '******************** ERROR CREATING HISTORY TABLE FOR TABLE: ' + @TableName + ' **************************************'
RETURN -1
END


IF @CreateTrigger = 'Y'
BEGIN
-- create history trigger
SET @SQLTrigger = '/************************************************************************************************************' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'Created By: ' + SUSER_SNAME() + @CRLF
SET @SQLTrigger = @SQLTrigger + 'Created On: ' + @Date + @CRLF
SET @SQLTrigger = @SQLTrigger + 'Comments: Auto generated trigger' + @CRLF
SET @SQLTrigger = @SQLTrigger + '***********************************************************************************************/' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'CREATE TRIGGER [Trigger_' + @TableName + '_UpdateDelete] ON DBO.' + @TableName + @CRLF
SET @SQLTrigger = @SQLTrigger + 'FOR UPDATE, DELETE' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'AS' + @CRLF + @CRLF
SET @SQLTrigger = @SQLTrigger + 'DECLARE @Action CHAR(1)' + @CRLF + @CRLF
SET @SQLTrigger = @SQLTrigger + 'IF EXISTS (SELECT ' + @FirstField + ' FROM Inserted)' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'BEGIN' + @CRLF
SET @SQLTrigger = @SQLTrigger + @TAB + 'SET @Action = ''U''' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'END' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'ELSE' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'BEGIN' + @CRLF
SET @SQLTrigger = @SQLTrigger + @TAB + 'SET @Action = ''D''' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'END' + @CRLF + @CRLF
SET @SQLTrigger = @SQLTrigger + 'INSERT INTO History_' + @TableName + @CRLF
SET @SQLTrigger = @SQLTrigger + @TAB + '(' + @FieldList + ', HistoryCreatedOn, HistoryCreatedByUserName, HistoryAction)' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'SELECT ' + @FieldList + ', GETDATE(), SUSER_SNAME(), @Action' + @CRLF
SET @SQLTrigger = @SQLTrigger + 'FROM DELETED'


--PRINT @SQLTrigger

-- execute sql script to create update/delete trigger
EXEC(@SQLTrigger)

IF @@ERROR <> 0
BEGIN
PRINT '******************** ERROR CREATING HISTORY TRIGGER FOR TABLE: ' + @TableName + ' **************************************'
RETURN -1
END

END

View 13 Replies View Related

Job History

Jul 24, 2001

The 'view job history' on Enterprise Manager is showing me only 4 or 5 run histories. I want to see more history on each of the jobs.Even I changed the limit to 10000 lones from 1000 lines on the server properties in the job system option, I am still seeing only the last 4 or 5 histories for each job(there are a total of 70 jobs on the server).Any ideas??Thanks.
Reddy.

View 1 Replies View Related

Job History Not There

May 15, 2000

Anyone tell me why some of my SQL-agent jobs have no history?
Some jobs are reporting history fine, others say "No history"

View 4 Replies View Related

Job History

Jul 6, 2000

I have set up a job as sa.After that I changed the sa password.Now I am not able to view the job history since then.Do i need to delete the job and reschedule it?

View 1 Replies View Related

SQL Job History ???

Aug 18, 2004

I have a question about the sql job history. I have a sql 2000 server that was recording all the job history on my sql jobs just fine until the other day. Today I checked the history and the jobs didnt show the past history anymore. Just today's history. So if the job didnt run today there is no history for that particular job. This isn't true, the job was run a few days ago. I know that no one went in and cleard the history on the jobs. What causes this issue, is there a way to not make this happen in the future? Is there a way I can recover the past history for my jobs.

Thanks for your time!! TIA

View 11 Replies View Related

Where To See Job History

May 16, 2012

i have my job running every 5 min. I want to view the history log. In job history it shows only few hundreds of records.. But i want to see from beginning. where to view whole log of job history?

View 8 Replies View Related

Database History

Jan 14, 2008

hello,
I'm am looking for a smart solution for keeping history of changes in records in my sql database. Not only history of a record but also which user caused the change and when (I have the username in session).
for now I added 4 fields to each table: "created by","created on","cancelled by",cancelled on", when the user create a record the 2 first fields are filled and and a user delete a record the two last fields are filled and the record is not really deleted but it won't be shown again (I'm using "where createdby is null").
this solution is taking the performance down and it does not solve the editing record tracking. creating new records and cancelling old ones for editing/changing solve that but than I m having problems with the primary key and relations to other tables.
I tried also to use a table that holds records that descirbes every change in records in my tables. it's very hard to search old data that way.
I know that oracle databases has a smart solution for history...   please someone advise me..
Elad.

View 1 Replies View Related

Maintaining History

Jun 11, 2008

hi ,
i am working on an application using c#, visual studio 2005, sql server 2005.
i have a few tables in sql server 2005.
i need to save the history. (i.e) all the inserts, updates, and deleats performed on the tables.
can any one suggest me how can i achieve that.
should i use triggers and save the changes in another table ???
waiting for your suggestion??
thank you

View 13 Replies View Related

Keeping Job History ...

Aug 26, 2002

SQl7, sp3, NT4

How do I keep th job history of a job, say if I re-create the job?

We recreate the jobs often as part of a code move, but I'd like to retain the history of the previous jobs?

** sp_help_jobhistory -- only shows the jobs that exist, and not old jobs that no longer reside on the server.

Thanks,
AJ

View 1 Replies View Related

Procedure History

Sep 12, 2000

Hi,
I want to know where the history of stored procedures stored, I mean yesterday I created one procedure and today I dropped that procedure and recreate it, I checked in sysobjects table name,crdate it shows only the creation date of the procedure. Where can I find the Modification date or something related to procedure history.


Thanks in Advance,

Seenu

View 4 Replies View Related

Conflict History

Feb 13, 2001

Hi

I'm using merge replication between 10 SQL server 7.0 SP2 machines. One central server is the publisher and 9 subscribers. I’ve setup an alert to get a message in case of conflicts. I defined it to trigger everytime the performance counter conflicts/sec rises above 0.

After some experimenting this seems now to work reliable, but there is still one point which bothers me. All conflicts are kept in the conflict history and everytime I get a message through the alert the number of copnflicts stated in the message increases by one.
Also if I open view replication conflicts in EM all conflicts can still be viewed even those I manually resolved. I can't even find a way to seen which conflicts are new ones and which have been resolved already. Does anybody know a way how to reset this numbers without going through all the conflict tables.

Markus

View 1 Replies View Related

Scheduled Job History

Oct 4, 2000

In SQL 6.5, when a scheduled job failed, you could see the error message in the history. In SQL 7.0, it simply tells you which was the last step to run. Is there a place which will report the actual error message generated by the task?

View 4 Replies View Related

Job History...URGENT!!

Jul 6, 2000

I have set up a job as sa.After few days I changed the sa password.Now I am not able to view the latest job history since then.It says the last run as 'succeeded',but it is not showing the latest history since the time I changed the password.It still shows the previous history only.Do I need to delete the job and reschedule it?
Thanks!

View 2 Replies View Related

Where&#39;s Task History In 7.0?

Aug 25, 1999

I feel stupid asking this because I have worked with SQL Server 6.0/6.5 for serveral years now, but I can't seem to find the task history in 7.0. When I look at a task, I can tell if each step ran or not, but I am used to seeing error messages upon failure by right-clicking on the task and choosing history.

How do I find this in 7.0? In casual looking for a few days, I've come up empty.

Thanks.

View 2 Replies View Related

SQL Job History To HTML

Apr 21, 1999

I heard there is a way to publish the results of SQL 7 jobs to HTML files.
has anyone tried this

View 1 Replies View Related

View Job History

Aug 19, 2000

Hi
I have a full database backup scheduled at 2AM in the morning
everyday and If I see that job status in Sql Server logs
current activity , it shows me that database has been backed
up at 2AM....But the problem is when I go to jobs and try to
do a view job history it doesn't give me the details of the
job and I didn't clear the job history..Can anyone tell me the
reason why it doesn't show me the job history.

Thanks
RAGHU

View 2 Replies View Related

DB Expansion History

Feb 15, 1999

Hi -
In order to restore a DB on another system I need to know the exact expansion history of the source DB in order to create/expand the devices on the target system the same way...
Is there a way for me to see the history of expansions I did on a DB ??
Tanx,
Paul

View 6 Replies View Related

Tracking The History Of Changes.

Sep 11, 2006

Hi all,

I have several transaction tables on which I need to track the changes. That is I need to maitain
the history of changes. Only few column values are changed often.

Which is the best way for tracking the changes.

1.Store the whole record after the change ?

Or

2.Store the ColumnName & its respective old & new value ?

Or any other better.

Note : UI part & SP's will take care of the tracking & no plans for triggers.

Thanks in advance,

HHA

View 2 Replies View Related

Cube History

Mar 25, 2004

I am trying to build a cube to monitor the sales performance. My measure is the sale amount. My dimensions include 1) Time 2) Sale hierarchy (salesman, sales office, region), and 3) Product Line. The problem I have is that when the salesman move from one office to another, the sales occured before this movement should continue to be credited to the old office. Only sales happen after the movement should be credited to the new office.
How should I implement the cube to achieve this effectively? We have more that 40,000 sales, about 500 offices, in the company to monitor. So I don't think keeping a copy of the sales hierarchy whenever there is a change is feasible.

Any inputs will be highly appreciated!

Thanks.

View 3 Replies View Related

Linkserver History

Jun 18, 2008

Hi Gurus,

How can i get linkserver history as when was link server created, lastmodified datae...etc...


Thanks,
ServerTeam

View 2 Replies View Related

System History

Nov 9, 2005

I have a table with video information
(
Name varchar(30) null,
Serial_no int(12) null,
Agency_no int(8) null,
Agency varchar(30) null
)
When items are damaged they are sent to our agency #5. I would like view not only the items that are assigned to our Agency but also what Agency owned this equipment BEFORE us.

M. Almeida

View 1 Replies View Related

Sql Statment History

Mar 1, 2006

I wanted to knw how to get the last 10 SQL Statments issued by the
users client to the SQL Server.


dbcc inputbuffer (spid) gives us the last statement how to get a
history of statments by a SPID.

View 2 Replies View Related

No Job History In SQL Agent Job

May 1, 2007

Hi Everyone,

I don't know why I cannot see any job hisotry after schedule job complete. any idea to fix it? thx

View 2 Replies View Related

Job History Disappeared

Dec 17, 2007

Today when I tried to troubleshoot a failed job, I found out that the job history is disappreared. Some jobs' history still exist. Does anybody have idea what happened? How can I fix it?

Thanks a lot.

View 4 Replies View Related

Error History?

Apr 2, 2008

Is there a place where SQL Server logs errors? When I run my Access MDBagainst a SQL 7 back end, I get ODBC errors, which are sometimes a littledescriptive, sometimes not at all. I usually have to execute code directlyagainst the back end to find out what's really going on. And that's if I'mable to reproduce the error. It would be helpful if SQL logged all errors itgenerates, or if something like that can be set up.Thanks,Neil

View 1 Replies View Related

Scheduled Job History

Jul 20, 2005

Is there a way to increase the number of records preserved in jobhistory? I have 82 jobs on my box, 30 of them run every 20 minutesfor 23 hours a day, every 30 days. Another 30 run once, every 30days. The system seems to have a limit of 50 history records for anyjob that hasn't run since yesterday and purges all history records ifthe job is more than a week old. I didn't know if there might be aconfiguration record buried in MSDB or somewhere else that would allowme to increase this size or perhaps a system SP that prunes jobhistory that I could modify.It isn't critical as the system is set to notify me when jobs fail,but still, I'd like to be able to look at a given day and verify thateverything went normally.

View 1 Replies View Related

History Blocks?

Mar 21, 2007

Is it possiable to go through the history blocks and change field names?...ie

I want to change "PS001_Pump1.RT_Daily" to "PS001_Pump1.Runtime_Daily"

so i can access the historical data thru the new tagname.

If so , is this using an udpate query?

View 1 Replies View Related

History Files

Oct 17, 2007

Hi All,

When I create snapshots in reports and choose to keep history files, where are these previous files going to be stored physically?

Thanks

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved