Tuesday, November 24, 2015

Script out Multiple jobs at at time to create on another server

 To script all jobs:

Step1:  ‘Object Explorer Details’ from the View menu in SSMS, or press the F7 key.
Step2: Click on any job in the Object Explorer window and a list of all the agent jobs appears in the ‘Object Explorer Details’ window.

Select all the jobs you want to script (press the Ctrl button while clicking to select individual jobs) and then right click and select the scripting option you want. 


This will then create all the selected jobs as a single query. You can script to a query window. 

Friday, November 20, 2015

Add one table to existing publication



use dbname
go
EXEC sp_changepublication
@publication = ' Pub_name',
@property = N'allow_anonymous',
@value = 'false'
GO


EXEC sp_changepublication
@publication = 'pub_name'
@property = N'immediate_sync',
@value = 'false'
GO

EXEC sp_addarticle  @publication = N'Pub_name',
@article = N'Time',
@source_object=N'Time'
GO

 --same above if you another table


--Should run on publisher
EXEC sp_refreshsubscriptions @publication = N'Pub_name'
GO

 ----Should run on publisher
EXEC sp_startpublication_snapshot @publication = N'Pub_name'
go







---take out table from replication
--remove table from replication
 EXEC  sys.sp_dropsubscription
    @publication = N'Pub_name',
    @article = N'Time',
    @subscriber = N'SQL4',
    @destination_db = 'db_name'' ;
GO


EXEC sys.sp_droparticle
    @publication = N'Pub_name',
    @article = N'Time',
    @force_invalidate_snapshot = 1 ;
GO

Grant Read or write access to only 1 table

Follow below steps:
1. Create login, and Add to public to ABC database
2.Grant Select , insert, update , delete on Tablename to Login 
Note: if you add login to db_reader group, the user will have Read access to all Database tables.

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...