Sunday, 7 January 2018

How to Configure Transnational Replication with Multiple Publishers, Single Subscriber



While providing a replication solution to one of my client in SQL Server 2016, I came across a scenario where the client had retail stores at various locations and all data from those stores had to be synchronized at a central location in real time. The aim of this synchronization was to make it easy for senior management to analyze all stores performance from a single location. After giving considerations to different options, I finally came up with a solution that worked for my client.

Let’s assume we have server  RBTSERV1 and RBTSERV2, which will act as publisher for 2 stores. RBTSERV3 will act as a subscriber and data from both servers RBTSERV1 and RBTSERV2 will be synchronized to RBTSERV3.

There were several tables that needed to be synchronized but to keep it simple, I will take 1 table in our example.

Notice that All stores have a unique StoreId assigned to them.Let’s create some sample table and data on all servers.

--RBTSERV1:PUBLISHER 1
create database DBPub1
use DBPub1
create table CustomerOrders(StoreID int ,OrderId int, ItemName varchar(100), Qty int, OrderDate datetime default getdate()
, CONSTRAINT PK_CustomerOrders PRIMARY KEY (StoreID,OrderId))

INSERT INTO CustomerOrders VALUES (1,1,'Books',5,Getdate())
INSERT INTO CustomerOrders VALUES (1,2,'Toys',3,Getdate())
---------------------------------
--RBTSERV2: PUBLISHER2
create database DBPub2
use DBPub2
create table CustomerOrders(StoreID int ,OrderId int, ItemName varchar(100), Qty int, OrderDate datetime default getdate()
, CONSTRAINT PK_CustomerOrders PRIMARY KEY (StoreID,OrderId))

INSERT INTO CustomerOrders VALUES (2,1,'fans',15,Getdate())
INSERT INTO CustomerOrders VALUES (2,2,'pens',13,Getdate())
---------------------------------
--RBTSERV3:SUBSCRIBER
create table CustomerOrders(StoreID int ,OrderId int, ItemName varchar(100), Qty int, OrderDate datetime default getdate()
, CONSTRAINT PK_CustomerOrders PRIMARY KEY (StoreID,OrderId))

So publisher RBTSERV1 has 2 records in the table and publisher RBTSERV2 also has 2 records in the table. Subscriber doesn’t have any records.

Now let’s start with our replication.

Configuring Publication on RBTSERV1:
To setup a publication on RBTSERV1, Follow the below steps:
1.       Right Click on folder “Local Publication” and select “New Publication...”



2.       In the publication wizard, select the database to be used for Publication. In our case, we are using DBPub1.



3.       Since we have to make the sync almost real time, so we choose Transaction replication.





4.       Next we pick the table we wish to use for our replication. Here the important point is to choose the “Properties for all Table Articles” under “Article Properties” as below:
Action if name is in use: Keep Existing Object Unchaged



5.       Next we leave the “Create a Snapshot Immediately...” option unchecked.




6.       Under Agent security, choose the options below. Note that on my server, SQL and Agent services are running under administrator account.




7.       Give your publication a name and click Finish.



8.       The publication wizard should finish without any error.




9.       Next repeat the same steps for RBTSERV2 and give your publication a name SERV2_Publication.
10.   Now right click on Publication SERV1_Publication and choose “New Subscriptions...”.  In the Subscription wizard, choose your publication as SERV1_Publication





11.    Then you select if you wish to have a push or pull subscription. Here I have used Push Subscriptions






12.   Now you select your subscriber name and the subscription database. Here I have used RBTSERV3 as subscriber and DBSubs as subscriber database.



13.   Configure the distributor Agent security.



14.   Choose to run the distributor Agent Continuously.



15.   It is important not to initialize the subscription as we will be manually synchronizing the old data.




16.   Finally finish the subscription wizard.



17.   Now if you check the log reader agent status of RBTSERV1 or RBTSERV2, you should see it running fine. 



18.   And now if you check data in subscriber table using below query, there should be no data. SELECT *   FROM [DBSubs].[dbo].[CustomerOrders]

Now let’s add some new records to both servers.

--RBTSERV1
INSERT INTO CustomerOrders VALUES (1,5,'notebooks',15,Getdate())
--RBTSERV2
INSERT INTO CustomerOrders VALUES (2,6,'erasers',150,Getdate())


19. Now finally check that the new records from both stores have come to subscriber table.



20.   Now you can sync the old records from both stores either using a SQL query or export import wizard. Now in future if you wish to reinitialize just one store, you may delete the data of that store from subscriber and manually sync the data from that store using queries
or export import wizard.


 So that's that. Hope it helped. If you have any issue in understanding the article, feel free to contact us and we will surely help you. Call or whatsapp - +91 997148322

email- support@redbushtechnologies.

Author- Suresh Kumar - A seasoned SQL DBA with more than 15 years of experience in working with fortune 500 MNCs.

Thank you
Team RedBush



Sunday, 17 December 2017

Which Indexes are required for SQL Server Query ?

'


A lot of time Jr. DBA/Developer and students are not clear which Index should be created for performance tuning a query. In my last 16 years as SQL DBA, I have taken more than 500 interviews at different levels and I have seen that even very Senior DBA are not clear at times as to what index will properly support my query.

So let’s see a very brief and clear explanation on what index will improve performance of my query and why:
We will use the below Sample queries:

CREATE TABLE [dbo].[Buildings](
       [Buildingid] [int] NOT NULL,
       [BuildingName] [varchar](50) NULL,
       [BuildingLocation] [varchar](50) NULL,
PRIMARY KEY CLUSTERED
(
       [Buildingid] ASC
)
)


--INSERT SOME RECORDS
INSERT INTO Buildings values (1,'Empire State','NYC')
INSERT INTO Buildings values (2,'Building2','NDLS')
INSERT INTO Buildings values (3,'Building3','NDLS')
INSERT INTO Buildings values (4,'Building4','Mumbai')
INSERT INTO Buildings values (5,'Building5','Mumbai')
INSERT INTO Buildings values (6,'Building6','Mumbai')
INSERT INTO Buildings values (7,'Building7','LA')
INSERT INTO Buildings values (8,'Building8','LA')
INSERT INTO Buildings values (9,'Building9','LAS')
INSERT INTO Buildings values (10,'Building10','LAS')

--Clustered Index Seek
select Buildingid FROM Buildings WHERE Buildingid=1




As you can see above, since we have where clause on Clustered Index and SELECT also have a clustered column, a clustered Index seek will happen.


--Clustered Index Scan
select Buildingid FROM Buildings WHERE BuildingName='Empire State'



Now since where clause has a non clustered column, there is no way for query optimizer to fetch data for BuildingName. So as shown above, entire clustered index will be scanned. NOTE that clustered index in nothing but table itself which is sorted based on some column, BuildingId here.

--Create a supporting Index
create index IDX_Buildings_BuildingName on Buildings(BuildingName)

--Scan Is converted to non clustered Index Seek
select Buildingid FROM Buildings WHERE BuildingName='Empire State'


As you can see above, Scan Is converted to non clustered Index Seek and new index is used.


--A scan or Lookup

select BuildingLocation FROM Buildings WHERE BuildingName='Empire State'


The above query will give Clustered Index Scan or a Key Lookup depending upon amount of data. Here data is less, so optimizer decides to do a scan . Why this Happened? Because BuildingLocation is not part of any index. So there is no way for optimizer to get this data, so it has to do a scan. To do away with this scan, we need to create a covering index.
--Covering Index
create index IDX_Buildings_BuildingName2 on Buildings(BuildingName) INCLUDE(BuildingLocation)
--A Perfect Seek now
select BuildingLocation FROM Buildings WHERE BuildingName='Empire State'


Now the index IDX_Buildings_BuildingName2 is used and a perfect seek happens because query has all supporting indexes now.
Now do we really need IDX_Buildings_BuildingName any more. Not actually. Figure out why not.

Saturday, 16 December 2017

Best Java Training Classes in Gurgaon | Why Learn Java ?





If you are not coming from C and C++ background, and want to learn your first programming language, I will suggest to choose Java. In this article, We will share our list of reason, and why you should learn Java programming and why we think Java is best programming language created ever.





1) Java is Easy to learn
Many would be surprised to see this one of the top reason for learning Java, or considering it as best programming language, but it is. If you have a steep learning curve, it would be difficult to get productive in a short span of time, which is the case with most of professional project.

Java has fluent English like syntax with minimum magic characters e.g. Generics angle brackets, which makes it easy to read Java program and learn quickly.

Once a programmer is familiar with initial hurdles with installing JDK and setting up PATH and understand How Classpath works, it's pretty easy to write program in Java.

2) Java is an Object Oriented Programming Language
Another reason, which made Java popular is that it's an Object Oriented Programming language. Developing OOPS application is much easier, and it also helps to keep system modular, flexible and extensible.

Once you have knowledge of key OOPS concept like Abstraction, Encapsulation, Polymorphism and Inheritance, you can use all those with Java. Java itself embodies many best practices and design pattern in it's library.

Java is one of the few close to 100% OOPS programming language. Java also promotes use of SOLID and Object oriented design principles in form of open source projects like Spring, which make sure your object dependency is managed well by using dependency Injection principle.

3) Java has Rich API
One more reason of Java programming language's huge success is it's Rich API and most importantly it's highly visible because come with Java installation. When I first started Java programming, I used to code Applets and those days Applets provides great animation capability, which amazes new programmer like us, who are used to code in Turbo C++ editor. Java provides API for I/O, networking, utilities, XML parsing, database connection, and almost everything. Whatever left is covered by open source libraries like Apache Commons, Google Guava, and others.

4) Powerful development tools e.g. Eclipse , Netbeans
Believe it or not, Eclipse and Netbeans has played a huge role to make Java one of the best programming languages. Coding in IDE is a pleasure, especially if you have coded in DOS Editor or Notepad.

They not only helps in code completion but also provides powerful debugging capability, which is essential for real world development. Integrated Development Environment (IDE) made Java development much easier, faster and fluent. It's easy to search, refactor and read code using IDEs.

Apart from IDE, Java platform also has several other tools e.g.. Maven and ANT for building Java applications, decompilers, JConsole, Visual VM for monitoring Heap usage etc.

5) Great collection of Open Source libraries
Open source libraries ensures that Java should be used everywhere. Apache, Google, and other organization has contributed lot of great libraries, which makes Java development easy, faster and cost effective.

There are framework like SpringStrutsMaven, which ensures that Java development follows best practices of software craftsmanship, promotes use of design patterns and assisted Java developers to get there job done.

I always recommend to search for a functionality in Google, before writing your own code. There is good chance that, it's already coded, tested and available for ready to use.

6) Wonderful community support
Community is the biggest strength of Java programming language and platform. No matter, How good a language is, it wouldn't survive, if there is no community to support, help and share there knowledge. Java has been very lucky, it has lots of active forums, Stackoverflow, open source organizations and several Java user group to help everything.

There is community to help beginners, advanced and even expert Java programmers. Java actually promotes taking and giving back to community habit. Lots of programmers, who use open source, contribute as commiter, tester etc. Expert programmer provides advice FREE at various Java forums and stackoverflow. This is simply amazing and gives lot of confidence to a newbie in Java.

7) Java is FREE
People like FREE things, Don't you? So if a programmer want to learn a programming language, or a organization wants to use a technology, COST is an important factor. Since Java is free from start, i.e. you don't need to pay anything to create Java application. This FREE thing also helped Java to become popular among individual programmers, and among large organizations. Availability of Java programmers is another big think, which makes organization to choose Java for there strategic development.

8) Excellent documentation support - Javadocs
When I first saw Javadoc, I was amazed. It's great piece of documentation, which tells lot of things about Java API. I think without Javadoc documentation, Java wouldn't be as popular, and it's one of the main reason, Why I think Java is best programming language.

Not every one has time and intention to look at code to learn what a method do . RedBush Tech made learning easy, and provide an excellent reference while coding in Java. With advent of IDE, you don't even need to look Javadoc explicitly in browser, but you can get all information in your IDE window itself.

9) Java is Platform Independent
In 1990s, this was the main reason of Java's popularity. Idea of platform independence is great, and Java's tag line "write once run anywhere" was enticing enough to attract lots of new development in Java. This is still one of the reason of Java being best programming language, most of Java applications are developed in Windows environment and run in UNIX platform.

10) Java is Everywhere
Yes, Java is everywhere, it's on desktop, it's on mobile, it's on card, almost everywhere and so is Java programmers. I think Java programmer out number any other programming language professional. Though I don't have any data to back this up, but it's based on experience. This huge availability of Java programmers, is another reason, why organization prefer to choose Java for new development than any other programming language.

Having said that, programming is very big field and if you look at C and UNIX, which is still surviving and even stronger enough to live another 20 years, Java also falls in same league. Though there are lot of talk about functional programming, Scala and other JVM languages, but they need to go a long way to match community, resources and popularity of Java. Also OOPS is one of the best programming paradigm, and as long as it will be there Java will remain solid.

To get help in Java NetBeans projects and Java classes for 2nd Semester, you can contact - 997148322 or email- support@redbushtechnologies.com

Thank you
Team RedBush

Wednesday, 22 November 2017

C++ Project for 11th,12th CS students- Student Report Card Download FREE



This C++ mini project on STUDENT REPORT CARD has student class with data members like roll no, name, marks and grade. Member functions in this class are used for accept / display details of students and a function to calculate grade based on marks obtained by student. Student Records are stored in binary file. This menu driven program illustrates read, write, search, modify and delete operations in binary file.

To Download Click - http://redbushtechnologies.com/CPP-Projects-gurgaon.php

If you didnt understand anything, feel free to write or call us at 9971483222

Team RedBush

Tuesday, 7 November 2017

ASP.NET C# SQL Server Project : Online Movie Ticket Booking : For B.tech, M.tech, MCA, BCA Final year students








Dear Students, above mentioned project is fully documented with detailed report and source code. It is based on ASP.NET, C# and SQL Server as database. Any student who wants to submit this as their final year project can contact us at - +91 9971483222 .

Saturday, 4 November 2017

SQL DBA Training Review by New Zealander John Williams


John O'Williams flew from New Zealand for a fast track course on Microsoft SQL DBA . Listen to what he says and how he rates our trainer Mr Suresh.

If you want to enroll in a very economical course from a champion trainer , feel free to contact us at -

support@redbushtechnologies.com or register at - http://redbushtechnologies.com/contactus.php

Thank you