Click here to Skip to main content
15,900,110 members
Home / Discussions / Database
   

Database

 
GeneralRe: Problems with CREATE DATABASE Pin
Colin Angus Mackay9-Mar-04 5:39
Colin Angus Mackay9-Mar-04 5:39 
GeneralRe: Problems with CREATE DATABASE Pin
Frederick S Jones11-Mar-04 2:08
Frederick S Jones11-Mar-04 2:08 
GeneralGenerating SQL script Pin
Asad Hussain9-Mar-04 2:51
Asad Hussain9-Mar-04 2:51 
GeneralRe: Generating SQL script Pin
Colin Angus Mackay9-Mar-04 5:34
Colin Angus Mackay9-Mar-04 5:34 
QuestionOracle Notification Services?? Pin
Chen Venkataraman8-Mar-04 9:43
Chen Venkataraman8-Mar-04 9:43 
GeneralFind right Sql Collation Problem !! Pin
MasudM8-Mar-04 5:49
MasudM8-Mar-04 5:49 
GeneralHi, everyone. I need help about SQL 2000 server. Pin
jlizardo8-Mar-04 4:01
jlizardo8-Mar-04 4:01 
GeneralRe: Hi, everyone. I need help about SQL 2000 server. Pin
Rob Graham8-Mar-04 8:56
Rob Graham8-Mar-04 8:56 
What you want to do is add a scheduled task for SQLServerAgent, and let it do the backup on a scheduled basis. If you have enterprise manager, use the database amintenace wizared to create the backup jobs. If not the TSQL code below will create a weekkly backup schedule, rotating the backup file name and overwiting the oldest. (there is a better way to do this, sql can manage the retention for you, but this is all I had handy)

BEGIN
  BEGIN TRANSACTION
  DECLARE @JobID BINARY(16)
  DECLARE @ReturnCode INT
  SELECT @ReturnCode = 0
  IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'[Uncategorized (Local)]') < 1
	  EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'

  -- Delete the job with the same name (if it exists)
  SELECT @JobID = job_id FROM   msdb.dbo.sysjobs WHERE (name = N'MyDatabase backup1')
  IF (@JobID IS NOT NULL) BEGIN
-- Check if the job is a multi-server job
	IF (EXISTS (SELECT  *
          FROM    msdb.dbo.sysjobservers
          WHERE   (job_id = @JobID) AND (server_id <> 0)))
	BEGIN
	-- There is, so abort the script
		RAISERROR (N'Unable to import job ''MyDatabase backup1'' since there is already a multi-server job with this name.', 16, 1)
		GOTO QuitWithRollback
	END
	ELSE
	-- Delete the [local] job
		EXECUTE msdb.dbo.sp_delete_job @job_name = N'MyDatabase backup1'
		SELECT @JobID = NULL
	END

BEGIN

	-- Add the job
	EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT , @job_name = N'MyDatabase backup1', @owner_login_name = N'sa', @description = N'No description available.', @category_name = N'[Uncategorized (Local)]', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

	-- Add the job steps
	EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 1, @step_name = N'Step 1', @command = N'sp_Hmx_BackupDb ''MyDatabase'',''D:\Database\DbBackups'',''MyDatabase1.BAK''', @database_name = N'MyDatabase', @server = N'', @database_user_name = N'', @subsystem = N'TSQL', @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 0, @output_file_name = N'', @on_success_step_id = 0, @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
	EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1

	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

	DECLARE @stDate as int	-- default job start date is today
	SET @stDate=0
	DECLARE @today as datetime
	set @today = DATEADD(day,0,GETDATE())		-- get start date
	set @stDate = DATEPART(yy,@today)*10000 + DATEPART(mm,@today)*100 + DATEPART(day,@today)
	-- Add the job schedules
	EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id = @JobID, @name = N'backup1', @enabled = 1, @freq_type = 4, @active_start_date = @stDate, @active_start_time = 010000, @freq_interval = 14, @freq_subday_type = 1, @freq_subday_interval = 0, @freq_relative_interval = 0, @freq_recurrence_factor = 0, @active_end_date = 99991231, @active_end_time = 235959
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

	-- Add the Target Servers
	EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

  END
  COMMIT TRANSACTION
  GOTO   EndSave
  QuitWithRollback:
  IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
  EndSave:
END
GO

-- Job Script generated by Cruncher - job |MyDatabase backup2|
-- Do Not Edit

BEGIN
  BEGIN TRANSACTION
  DECLARE @JobID BINARY(16)
  DECLARE @ReturnCode INT
  SELECT @ReturnCode = 0
  IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'[Uncategorized (Local)]') < 1
	  EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'

  -- Delete the job with the same name (if it exists)
  SELECT @JobID = job_id FROM   msdb.dbo.sysjobs WHERE (name = N'MyDatabase backup2')
  IF (@JobID IS NOT NULL) BEGIN
-- Check if the job is a multi-server job
	IF (EXISTS (SELECT  *
          FROM    msdb.dbo.sysjobservers
          WHERE   (job_id = @JobID) AND (server_id <> 0)))
	BEGIN
	-- There is, so abort the script
		RAISERROR (N'Unable to import job ''MyDatabase backup2'' since there is already a multi-server job with this name.', 16, 1)
		GOTO QuitWithRollback
	END
	ELSE
	-- Delete the [local] job
		EXECUTE msdb.dbo.sp_delete_job @job_name = N'MyDatabase backup2'
		SELECT @JobID = NULL
	END

BEGIN

	-- Add the job
	EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT , @job_name = N'MyDatabase backup2', @owner_login_name = N'sa', @description = N'No description available.', @category_name = N'[Uncategorized (Local)]', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

	-- Add the job steps
	EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 1, @step_name = N'Step 1', @command = N'sp_Hmx_BackupDb ''MyDatabase'',''D:\Database\DbBackups'',''MyDatabase2.BAK''', @database_name = N'MyDatabase', @server = N'', @database_user_name = N'', @subsystem = N'TSQL', @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 0, @output_file_name = N'', @on_success_step_id = 0, @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
	EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1

	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

	DECLARE @stDate as int	-- default job start date is today
	SET @stDate=0
	DECLARE @today as datetime
	set @today = DATEADD(day,7,GETDATE())		-- get start date
	set @stDate = DATEPART(yy,@today)*10000 + DATEPART(mm,@today)*100 + DATEPART(day,@today)
	-- Add the job schedules
	EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id = @JobID, @name = N'backup2', @enabled = 1, @freq_type = 4, @active_start_date = @stDate, @active_start_time = 010000, @freq_interval = 14, @freq_subday_type = 1, @freq_subday_interval = 0, @freq_relative_interval = 0, @freq_recurrence_factor = 0, @active_end_date = 99991231, @active_end_time = 235959
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

	-- Add the Target Servers
	EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
	IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

  END
  COMMIT TRANSACTION
  GOTO   EndSave
  QuitWithRollback:
  IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
  EndSave:
END
GO


Power corrupts and PowerPoint corrupts absolutely. - Vint Cerf
GeneralConnection Pooling Pin
Mazdak7-Mar-04 21:03
Mazdak7-Mar-04 21:03 
GeneralRe: Connection Pooling Pin
Rob Graham8-Mar-04 3:00
Rob Graham8-Mar-04 3:00 
GeneralRe: Connection Pooling Pin
Mazdak8-Mar-04 3:32
Mazdak8-Mar-04 3:32 
GeneralRe: Connection Pooling Pin
Rob Graham8-Mar-04 6:23
Rob Graham8-Mar-04 6:23 
GeneralRe: Connection Pooling Pin
Mazdak8-Mar-04 7:59
Mazdak8-Mar-04 7:59 
Generalunknown extension file Pin
aguest6-Mar-04 10:59
aguest6-Mar-04 10:59 
GeneralRe: unknown extension file Pin
josefg6-Mar-04 13:44
josefg6-Mar-04 13:44 
General.Data Provider for MySQL Pin
josefg6-Mar-04 4:35
josefg6-Mar-04 4:35 
GeneralRe: .Data Provider for MySQL Pin
Anonymous6-Mar-04 8:51
Anonymous6-Mar-04 8:51 
GeneralRe: .Data Provider for MySQL Pin
josefg6-Mar-04 23:21
josefg6-Mar-04 23:21 
GeneralSlightly off topic... choosing db server software Pin
Verdant1235-Mar-04 19:18
Verdant1235-Mar-04 19:18 
GeneralRe: Slightly off topic... choosing db server software Pin
Andy Harman9-Mar-04 10:23
Andy Harman9-Mar-04 10:23 
GeneralImporting Data in Bulk from SQL to Access Pin
Adnan5625-Mar-04 19:07
Adnan5625-Mar-04 19:07 
GeneralImporting Data in Bulk from SQL to Access Pin
Adnan5627-Mar-04 19:34
Adnan5627-Mar-04 19:34 
Generalusing LIMIT within a SELECT statment Pin
Matt Newman5-Mar-04 7:36
Matt Newman5-Mar-04 7:36 
GeneralRe: using LIMIT within a SELECT statment Pin
Henrik Stuart5-Mar-04 7:49
Henrik Stuart5-Mar-04 7:49 
GeneralRe: using LIMIT within a SELECT statment Pin
Matt Newman5-Mar-04 8:02
Matt Newman5-Mar-04 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.