Tuesday, July 15, 2014

Views

Introduction:
In this article we are going to discuss about the Views in the sql server 2005 version. It is one of the important elements in the sql server; it eliminates the difficulties in the business process. There are lots of significant improvements in the view especially in the sql server 2005 version. They have introduced the indexed views and INSTEAD of Trigger on the permanent view. Let us discuss about the views with more practical way.

Views:

The view is a virtual table, which can have the multiple columns from the one or more table. It can be used like the normal table. Normally view cannot store the data permanently in the table. When we create the view it stores the view definition schema as object under the concern database.

Let us see the syntax of the create view

CREATE VIEW View Name [Alias name1, name2,]

WITH ENCRYPTION

WITH SCHEMA BINDING

AS

SELECT statement [WITH CHECK OPTION]

The create view can be created with the view name and the alias can be given in the view name parameter parenthesis. The view schema can be stored in the encrypted format. Here is an option like SCHEMA BINDING; this is an important mile stone in the view to allow the developers to create the permanent view.

When to use VIEW?

When you have complex queries, that use many places in the stored procedures or functions, etc..,

It will be used as security mechanism in the web applications. When we use the original table in the web applications the hackers may drop the table. That time the original data will be persist in the table.

When you want to hide the particular columns to the specific people then we can create the specialized view.

Encrypted View:

The definition of schema will be encrypted and stored as object in the database. This can be done using the ENCRYPTION option in the view creation.

IF
 OBJECT_ID('[DBO].Vw_SqlObjects_Encrypted') IS NOT NULLBEGIN   DROP VIEW [DBO].Vw_SqlObjects_Encrypted   PRINT '<< [DBO].Vw_SqlObjects_Encrypted View dropped >>'ENDGOCREATE VIEW [DBO].Vw_SqlObjects_EncryptedWITH ENCRYPTIONAS   SELECT       O.Object_ID      ,O.Name      ,'Type' = CASE O.type WHEN 'S' THEN 'Scalar Functions'                          WHEN 'F' THEN 'Functions'                          WHEN 'V' THEN 'Views'                          WHEN 'PK' THEN 'Primary keys'                          WHEN 'TR' THEN 'Triggers'                          WHEN 'P' THEN 'Procedures'                          WHEN 'U' THEN 'User Defined Functions'                          WHEN 'TF' THEN 'Table Valued Functions'                          WHEN 'IF' THEN 'Inline Functions' END      ,O.create_date      ,O.modify_date      ,CASE WHEN SC.encrypted = 0 THEN 'No' ELSE 'Yes' END AS [IsEncrypted]      ,SC.text  FROM      SYS.OBJECTS O  INNER JOIN      SYSCOMMENTS SC ON SC.id = O.object_id  GOIF OBJECT_ID('[DBO].Vw_SqlObjects_Encrypted') IS NOT NULLBEGIN   PRINT '<< [DBO].Vw_SqlObjects_Encrypted View created >>'ENDGO
Now if you want to see the view schema definition for the above view is not possible. We have stored in the encrypted format. This is a significant option to hide the important calculations inside the view from the others.

In case of any alter in the view must be stored externally somewhere else. 

SELECT
 text FROM SYSCOMMENTS WHERE id = OBJECT_ID('[DBO].Vw_SqlObjects_Encrypted')
SELECT definition FROM SYS.sql_modules WHERE object_id =OBJECT_ID('[DBO].Vw_SqlObjects_Encrypted')
sp_helptext Vw_SqlObjects_Encrypted
If you execute the above queries then it will say like view is encrypted.

There are three types of views in the sql server 2005.

They are 
  1. Normal or Standard view
  2. Indexed or permanent view
  3. Partitioned view
Normal or Standard view:
This view is most frequently used by the developers. When create the view the schema will be stored an object in the database. When we retrieve the content from this virtual table, it will be executed the schema and stored the data from the parent table.

Here if you have the result from the same table then it can be updated and inserted. The deleted row will be reflected in the original table.

USE
 [Northwind]GOIF OBJECT_ID('[DBO].vw_ViewProducts','V') IS NOT NULLBEGIN  DROP VIEW [DBO].vw_ViewProducts  PRINT '<< [DBO].vw_ViewProducts view dropped.. >>'ENDGOCREATE VIEW [DBO].vw_ViewProductsAS SELECT     ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,
UnitsOnOrder,ReorderLevel,Discontinued
 FROM ProductsGOIF OBJECT_ID('[DBO].vw_ViewProducts','V') IS NOT NULLBEGIN  PRINT '<< [DBO].vw_ViewProducts view created.. >>'ENDGO--O/PSELECT * FROM [DBO].vw_ViewProducts--INSERTINSERT INTO[DBO].vw_ViewProducts(ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued)VALUES('Test View',1,2,'100 per bag',25.45,89,57,15,0)--DELETEDELETE FROM [DBO].vw_ViewProducts WHERE ProductID = 81
Here you can do the DML operations in the view when you have only one table. 

Indexed views:

The indexed or permanent view is one of the new features introduced in the sql server 2005 version. We have seen that the view only store the schema definition and it will get execute and load the data into the virtual table at the time of view used. But this view creates the permanent view and we can create the indexes on the table. It allows us to create the instead of trigger.

The indexed view can be created with the WITH SCHEMA BINDING option while creating the view.

The indexed view has some restrictions like cannot use the TOP, DISTINCT, UNION, ORDER BY and aggregate functions.

It allows us to use the GROUP BY statement but we cannot use COUNT statement. Instead of that COUNT_BIG statement can be used.

IF
 EXISTS(SELECT OBJECT_ID FROM SYS.OBJECTS WHERE OBJECT_ID =OBJECT_ID(N'[DBO].Vw_Product_Sales_Report',N'V'))BEGIN  DROP VIEW [DBO].Vw_Product_Sales_Report  PRINT '<< [DBO].Vw_Product_Sales_Report view dropped >>'ENDGOCREATE VIEW [DBO].Vw_Product_Sales_ReportWITH SCHEMABINDINGAS  SELECT       O.OrderID     ,C.CustomerID     ,C.CompanyName     ,C.Address+', '+C.City AS [Customer Address]     ,OD.ProductID     ,P.ProductName     ,OD.UnitPrice     ,OD.Quantity     ,(OD.UnitPrice * OD.Quantity) AS [Total]     ,(OD.UnitPrice * OD.Quantity) * OD.Discount/100 AS [Discount]   FROM     [DBO].Orders O (NOLOCK)   INNER JOIN [DBO]."Order Details" OD (NOLOCK) ON OD.OrderID = O.OrderID   INNER JOIN [DBO].Customers C (NOLOCK) ON C.CustomerID = O.CustomerID   INNER JOIN [DBO].Products P (NOLOCK) ON P.ProductID = OD.ProductIDGOIF EXISTS(SELECT OBJECT_ID FROM SYS.OBJECTS WHERE OBJECT_ID =OBJECT_ID(N'[DBO].Vw_Product_Sales_Report',N'V'))BEGIN  PRINT '<< [DBO].Vw_Product_Sales_Report view created >>'ENDGO
Here the  indexed view has created. When you retrieve the data from this table, it will execute like normal table.

There are some retrictions while creating this indexed view like the name of the view must be two part name and we cannot use select * in the view schema defintion.

Normally view cannot have the triggers but from the sql server 2005 onwards We can create the Instead of trigger on the instead of trigger.

Partitioned Views:

The partitioned view and its execution is like normal view. It will work across the database and across the server.

There are two types of Partitioned views. They are 
  1. Local Partitioned View
  2. Global Partitioned View

1. Local Partitioned View:
The local partitioned view can be created within same server but different database.

The view schema definition will be stored in the executed database. But when we try to retrieve the data from the table, it has to execute the schema definition internally and load the data.

Let us see an example.

USE
 [Northwind]GOCREATE TABLE EmployeeList(  iEmployeeID INT IDENTITY(1,1),  vFirstName VARCHAR(25) NOT NULL,  vLastName VARCHAR(25) NOT NULL,  iDeptID INT,  vAddress VARCHAR(25) NOT NULL,  vCity VARCHAR(25) NOT NULL,  vState VARCHAR(25) NOT NULL,  vCountry VARCHAR(25) NOT NULL,)GOUSE [Master]GOCREATE TABLE Department(  iDeptID INT IDENTITY(1,1) PRIMARY KEY,  vDeptName VARCHAR(50),  vDeptDesc VARCHAR(25),  vDeptAddedBy VARCHAR(50),  vPostedDate DATETIME DEFAULT GETDATE())GO--SELECT * FROM DepartmentUSE [Northwind]GOIF OBJECT_ID('[DBO].vw_LocalPartion_View','V') IS NOT NULLBEGIN  DROP VIEW [DBO].vw_LocalPartion_View  PRINT '[DBO].vw_LocalPartion_View view dropped...'ENDGOCREATE VIEW [DBO].vw_LocalPartion_ViewASSELECT E.iEmployeeID,E.vFirstName+SPACE(1)+E.vLastName AS [Name],       D.vDeptName,E.vAddress,E.vCity,E.vStateFROM EmployeeList E--INNER JOIN Master..Department D ON D.iDeptID = E.iDeptID --Either one of the way will be used.INNER JOIN Master.dbo.Department D ON D.iDeptID = E.iDeptIDGOIF OBJECT_ID('[DBO].vw_LocalPartion_View','V') IS NOT NULLBEGIN  PRINT '[DBO].vw_LocalPartion_View view created...'ENDGO--O/pSELECT * FROM [DBO].vw_LocalPartion_View 

2. Global Partitioned View

The global Partitioned view will work across the server. The view can be created to join the table across the server.

The accessing format will be like this.

[Server Name].  Database Name. Table Name

When we execute the view if it is not linked with the current server then it will ask us to link the external server.

The following system stored procedure will be used to link the server.

sp_addlinkedserver 
'Server name'
The following system catalog table is used to see the list of linked servers.

SELECT
 * FROM SYS.SERVERS
INSTEAD OF Triggers on the Indexed View

Normally the triggers cannot be created on the view. But sql server 2005 onwards we can create the INSTEAD OF trigger on the indexed views.

USE
 [Northwind]GOIF OBJECT_ID('[DBO].[VW_Trigger_Example') IS NOT NULLBEGIN   DROP VIEW [DBO].[VW_Trigger_Example]   PRINT '[DBO].[VW_Trigger_Example view dropped..'ENDGOCREATE VIEW [DBO].[VW_Trigger_Example]WITH SCHEMABINDINGAS  SELECT P.ProductID,P.ProductName,P.SupplierID,         OD.OrderID,OD.UnitPrice,OD.Quantity  FROM [DBO].Products P  INNER JOIN [DBO].[Order Details] OD ON OD.ProductID = P.ProductIDGOIF OBJECT_ID('[DBO].[VW_Trigger_Example') IS NOT NULLBEGIN   PRINT '[DBO].[VW_Trigger_Example view created..'ENDGO--SELECT * FROM VW_Trigger_ExampleIF OBJECT_ID('[DBO].Tr_Delete_TriggerExample','TR') IS NOT NULLBEGIN  DROP TRIGGER [DBO].Tr_Delete_TriggerExample  PRINT '[DBO].Tr_Delete_TriggerExample trigger dropped..'ENDGOCREATE TRIGGER [DBO].Tr_Delete_TriggerExampleON [DBO].VW_Trigger_ExampleINSTEAD OF DELETEASBEGIN   PRINT '----------------------------------------'   PRINT 'This is an example of INSTEAD OF Trigger'   PRINT '----------------------------------------'   SELECT TOP 1 * FROM DELETEDENDGOIF OBJECT_ID('[DBO].Tr_Delete_TriggerExample','TR') IS NOT NULLBEGIN  PRINT '[DBO].Tr_Delete_TriggerExample trigger created..'ENDGO--O/P--SELECT * FROM [DBO].[VW_Trigger_Example] WHERE ProductID = 11DELETE FROM [DBO].[VW_Trigger_Example] WHERE ProductID=11
How to view the Created Views?

There are few ways to view the scehema definition of the created views.

SP_HELPTEXT
 vw_LocalPartion_ViewSELECT id,text FROM SYSCOMMENTS WHERE id = OBJECT_ID('[DBO].vw_LocalPartion_View')SELECT object_id,definition FROM SYS.SQL_MODULES WHERE OBJECT_ID =OBJECT_ID('[DBO].vw_LocalPartion_View')
How to drop the View?

If you want to drop the view then you can use the following statement. When you drop the table underlying view will not be deleted. But if you run that view it will thrown an error.

DROP VIEW VIEW_NAME

How to alter the view?

If you want to do changes in the created views then you can alter the view whatever you want to view the same view name.

ALTER VIEW VIEW_NAME
AS
SELECT [Columns List]....
Conclusion:

So far, we have seen the views in the sql server 2005. I hope that, this has given enough idea about the views. If there is any correction or suggestions about this article please post your feedback.

Wednesday, July 9, 2014

Google puts foot down on porn ads


Internet giant Google has instituted new algorithms in its decade-old AdWords program, which enables ads to be placed through searches on the website, to make it more difficult to advertise pornographic material. The change comes on the heels of a larger effort by Google, started in 2013, to prevent bloggers from making money by posting ads for online pornographic material through the AdWords program.

In a statement to both individuals and organisations advertising using AdWords, Google stated, "Beginning in the coming weeks, we'll no longer accept ads that promote graphic depictions of sexual acts including, but not limited to, hardcore pornography; graphic sexual acts including sex acts such as masturbation."

The twist has caught most of the porn industry off-guard, with many of them viewing this change as an obstruction on the most popular and generally effective method of advertising porn. With many of the big porn corporations based in the US, lobbyists are claiming that such changes infringe upon their right of free speech.



Here we can see that on a simple local search, in Noida, of the word "massage", 3-4 advertisements pop up suggesting spa services and commercial massage parlours nearby.
But, specifying the search to say "sexy massage", we now see these advertisements disappear. This means that the majority of ads linking to those keywords were pornographic in nature.


This general trend by Google to reverse the expanding and free nature of internet pornography has been ongoing since 2012, when they announced the first major plans for safer searches through keyword manipulation. However, the pornographic content is still very much accessible through specific searches on the Google website and Google has subsequently denied any accusations of censorship.

Monday, July 7, 2014

New Android L release

New Android L release date and new features: Details announced at Google I/O


 Google launched Android 4.4 KitKat last September so we've investigated when the new Android version will be released, whether it's 4.5 or 5.0. Google has detailed Android L at it's I/O 2014 developer conference so there's lots to talk about. Read: How to get Android L now.
New Android L: Release date
Ok, first things first. It's unclear whether Google's new Android version will be 4.5 or 5.0 although the former is the favourite at the moment. It's thought that the name, following the alphabetical list of sweet treats, will be Lollipop. Previous versions include KitKat, Ice Cream Sandwich and Honeycomb. It's codenamed 'Moonshine'. See also: 30 best Android smartphones in UK: What's the best Android phone you can buy in 2014? 
Google has confirmed the existence of the next version of Android but is only calling it the 'Android L release'. It looks like we'll have to wait for a proper name. At I/O, the firm announced that Android L will arrive later this year in autumn.
For developers, the L developer preview is available now.
New Android L: Material Design
Google has revealed a new design language for the Android L release which is called 'material'. Overall, it's a cleaner and very Google style which developers can make use of in apps. The Roboto font can also be used anywhere. You'll notice that the new navigation buttons are a triangle, circle and square.
See also: First Android L screenshots: how the new material design looks on the Nexus 5.
Elements can now be given depth, so shadows and light sources affect user interface elements in real time. App interfaces will now feature touches of colour automatically generated based on the content and there are new animations and touch feedback.
You can see the new look in the above and main article images including new icons and new navigation buttons. Take a look at Google's video below to get an idea of what new Android L will look and feel like.


New Android L: New features
Enhanced notifications
Android L will make notifications even better. For starters you can get them on the lock screen - and they will be automatically ordered in priority. You will be able to swipe them away like normal or double tap to open the relevant app.
New lockscreen
Part of the Android L redesign is a new lockscreen which will show you notifications (see above image). You'll need to swipe up to unlock (if you don't have a lock pattern or other unlock method) but you can also swipe right to launch the dialler or left to launch the camera.
New multi-tasking
Forget a 2D list of open apps, the new recent apps section of Android L brings a Google Now card style layout. The open apps flow on a sort of carousel and can be swiped off to either side to close them as before.
It's not working on the developer preview but some apps, for example chrome, will be able to have multiple cards in recent apps. Android L will show a separate card for each open tab.
New notifcation bar
The Android L notification bar looks quite different to before. It works in the same way as before so a swipe from the top of the screen grants access. There's a new layout and colour scheme.
Instead of tapping a button to access quick settings you simply swipe downwards a second time. There is now screen brightness control as standard and a new 'cast screen' icon for mirroring with a Chromecast.
Security - personal unlocking
Google said that security is a key element for Android and its users. A new feature will enable users to unlock their smartphone when physically near enough a device like an Android Wear smartwatch. It's a bit like cars with keyless entry.

Battery life - new saver mode
Better battery life is something we always want and Google promises that Android L will bring it via a new battery saving mode. Project Volta will allow developers to identify how their apps are using battery so they make improvements.
Google said that the new battery saving mode will give a Nexus 5 an extra 90 minutes of power. The battery section of the settings menu now gives more detailed information, too.



Performance
As we expected, Android L will support 64-bit processors and it will also support the ART software library which Google says will be twice as fast as Davik.
view the video
http://www.youtube.com/watch?v=Q8TXgCzxEnw

iTi

Sunday, July 6, 2014

Writer's Block Tips

5 Ways To Help Beat Writer's Block


Have you ever thought of a topic you wanted to write about for your blog and you sat down to write the content and no words come out? You brainstorm and try to make yourself write, but you can't get your fingers to type on the keyword or write on paper? Don't feel alone. That is exactly what writer's block feels like and it can happen to any blogger (and any kind of writer) at some point and time.
When writer's block strikes you, try some of the following tips to get back into the flow of writing:
1. Take a Break and Be Creative
Clear your mind from the task at hand and do something creative. Make some updates to your website. Create an infographic you've been thinking of doing for your business. Work on customizing your social network backgrounds. Do any type of project that uses the creative part of your brain.
2. Exercise
Get blood pumping throughout your body and exercise. By doing this, it will get more oxygen to your brain and stimulate your mental process. Go for a mile or two walk. Do some housework you've been putting off. Try doing yoga to help clear your mind and help your body. Dance around the house like no one is watching. Just get your body moving so that your brain will move as well. When the blood that was diverted to your muscles to keep them going comes rushing back to your cerebral cortex, you will find it's one of the best times to get that flow of writing going again.
3. Free Writing
Begin writing about things just off the top of your head. It can be about the topic you are wanting to write about for your blog, it can be something completely unrelated. Take a blank piece of paper and whatever pops in your head, write it down. Just get your thoughts out. By doing this, it will help you get into the "state" of writing and then be able to write about your original topic.
4. Change of Scenery
Go to a different location to write. Sometimes a change in your environment will give you inspiration. Take a trip to your local library, grab a table or a computer (depends if you are handwriting or typing). Take your laptop and go to the park. Try out one of the local cafes. Even if there is no wi-fi where you go, you can write offline and upload the content when you get home. A change in your scenery can give you a fresh perspective on writing and help conquer that writer's block.
5. Time of Day
Change up the time that you work on writing your blog content. If you normally write in the evening, try writing in the morning. Change your schedule around. Breaking a habit like this may help you think in a different perspective and get you going in a brand new way. There are morning people that may think better in the mornings and then night owls that may be more productive in the evenings. Experiment... try writing during different times in the day and see which time works for you.
The next time you sit down to write content for your blog and the words just don't want to come out, try one of these tips to see if it helps you get back into the flow of writing. If one of them do not work, try another... maybe all five.
Writer's block is just a speed bump that you can overcome. You just need to determine what you can do to change the way your brain thinks and then get back into the flow of writing!
 For blogging and content marketing advice, http://fresh2jobtricks.blogspot.in/ visit my blog