Monday, August 29, 2011

Copy one table to another temporary table.....creation

SELECT * INTO TEMP FROM EmployeePersonal

SELECT * INTO TEMP1 FROM EmployeeOfficial

Create a Stored Procedure update the values at runtime.....

-----------------Create a Stored Procedure update the values at runtime.-----------

CREATE PROCEDURE UpdateEmployeeId
(@empno int,@newph int, @oldph int output)

AS

SELECT @oldph=Ph FROM EmployeePersonal WHERE Emp_No=@empno

IF(@oldph=@newph)
BEGIN
RETURN 0
END

ELSE

BEGIN
UPDATE EmployeePersonal SET Ph=@newph WHERE Emp_No =@empno
RETURN 1
END

------------Execution -----------
DECLARE @oldph int
DECLARE @returnvalue int
EXEC @returnvalue=UpdateEmployeeId 101,1,@oldph OUTPUT

SELECT @oldph 'oldphonenumber'
SELECT @returnvalue 'Returning value 1 or 0'

Create trigger and sp Update one table affected to another table..

-------// CREATE A NEW DATABASE ///------------
CREATE DATABASE ilinkchitharan

USE ilinkchitharan
--------------// CREATE TWO TABLES    ////------------
----// TABLE 1 EMPPERSONAL //-------
CREATE TABLE EmpPersonal
(
Emp_No int PRIMARY KEY IDENTITY (100,1),
Emp_Name VARCHAR(20),
Ph int
)

----// TABLE 2 EMPOFFICIAL //-------

CREATE TABLE EmpOfficial
(
Emp_No int FOREIGN KEY REFERENCES EmpPersonal(Emp_No)  IDENTITY (100,1),
Emp_Name VARCHAR(20),
Designation VARCHAR(25)
)
--------------
DROP TABLE EmpPersonal
-------------// INSERTING VALUES TO THE TABLES 1 //---------
INSERT INTO EmpPersonal VALUES('balaji',567345678)
INSERT INTO EmpPersonal VALUES('chitharan',4341354)
INSERT INTO EmpPersonal VALUES('ravi',34455678)
INSERT INTO EmpPersonal VALUES('naga',564353478)
INSERT INTO EmpPersonal VALUES('narenran',657345678)
INSERT INTO EmpPersonal VALUES('madhan',865345678)
INSERT INTO EmpPersonal VALUES('vinoth',234345678)
INSERT INTO EmpPersonal VALUES('basheer',85345678)
INSERT INTO EmpPersonal VALUES('bharath',165345678)

-------------// INSERTING VALUES TO THE TABLES 2 //---------


INSERT INTO EmpOfficial VALUES('balaji','softwareengg')
INSERT INTO EmpOfficial VALUES('chitharan','softwareengg')
INSERT INTO EmpOfficial VALUES('ravi','Tester')
INSERT INTO EmpOfficial VALUES('naga','Tester')
INSERT INTO EmpOfficial VALUES('narenran','Tester')
INSERT INTO EmpOfficial VALUES('madhan','softwareengg')
INSERT INTO EmpOfficial VALUES('vinoth','Tester')
INSERT INTO EmpOfficial VALUES('basheer','softwareengg')
INSERT INTO EmpOfficial VALUES('bharath','softwareengg')


--------
SELECT * INTO TEMP FROM EmployeePersonal
SELECT *FROM EmpPersonal
SELECT *FROM EmpOfficial

----------//  CREATE TRIGGER USING UPDATE TWO TABLES //--------------

ALTER TRIGGER Tupda
ON   EmpOfficial
AFTER UPDATE
AS
BEGIN

    UPDATE J SET J.Emp_Name = I.Emp_Name
     FROM
     inserted I inner join
     EmpPersonal J
     ON
     I.Emp_No = J.Emp_No
END

---
UPDATE EmpOfficial SET Emp_Name='balajisLALGUDI' WHERE Emp_No=100
UPDATE EmpOfficial SET Emp_Name='SCHITHARAN' WHERE Emp_No=101
UPDATE EmpOfficial SET Emp_Name='RAJA' WHERE Emp_No=103
UPDATE EmpOfficial SET Emp_Name='SUBRAMANI' WHERE Emp_No=104

------

--------------// CREATE TRIGGER USING INSERT VALUES IN TO TWO TABLE //--------
CREATE TRIGGER Tinsert
ON   EmpOfficial
AFTER INSERT
AS
BEGIN
    UPDATE J SET J.Emp_Name = I.Emp_Name from inserted I inner join
    EmpPersonal J ON I.Emp_No = J.Emp_No
END

-----------------
INSERT INTO dbo.EmpOfficial
(Emp_Name,Designation)
 values
('sasikumar','Tester')

--------// CREATE STORED PROCEDURE WITH MERGE CONCEPTS   ///---------------
CREATE PROC SP_update
AS
BEGIN
MERGE EmpOfficial AS TARGET
USING  EmpPersonal  AS new  ON  (TARGET.Emp_No=New.Emp_No )  WHEN  matched and 
TARGET.Emp_Name<>New.Emp_Name
THEN  UPDATE  SET
TARGET.Emp_Name=New.Emp_Name 
WHEN  not matched BY TARGET
THEN
INSERT(Emp_Name ) VALUES ( New.Emp_Name );
END
======================
SELECT*FROM EmpOfficial
SELECT*FROM EmpPersonal
UPDATE EmpPersonal set Emp_Name='Chhjjjjjjjjjen'where Emp_No=100
----------------------
Exec dbo.SP_update
=====================
merge EmpOfficial   as target  using  EmpPersonal  as new  on  (target.Emp_No=New.Emp_No )  when  matched and 
target.Emp_Name<>New.Emp_Name or
target.Designation<>New.Designation or
 then  update  set
target.Emp_Name=New.Emp_Name ,
target.Designation=New.Designation ,
 when  not matched by target then  insert(
Emp_No ,
Emp_Name ,
Designation ,
) Values (
New.Emp_No ,
New.Emp_Name ,
New.Designation ,
 );

 -------------------------------

Functions in SQL Server 2008

USE chitharans

SELECT *FROM EmployeeOfficial
SELECT *FROM EmployeePersonal
-------------Scalar value Function (return single value)----------
CREATE  FUNCTION Employeenumbers (@empno int)
RETURNS int
AS
BEGIN
DECLARE @returnvalue int
SELECT @returnvalue=Emp_No FROM EmployeeOfficial WHERE Emp_No=@empno
RETURN @returnvalue
END

----------

------Execution-----

SELECT dbo.Employeenumbers(101)
SELECT  1 AS number

-------------Inline Functions (return a table)------------

CREATE  FUNCTION Employeefunction (@empno int)
RETURNS TABLE
AS
RETURN SELECT *FROM EmployeeOfficial WHERE Emp_No=@empno


--------------Execution---------
SELECT *FROM EmployeeFunction(101)


-------------Table valued Funtions(Multiple operation, complex logic just like SP)---

CREATE  FUNCTION Employeetablevaluefunction12 (@empno int)
RETURNS @result TABLE(name VARCHAR(20))
AS
BEGIN
INSERT INTO @result(name)
SELECT [Emp_Name] FROM EmployeeOfficial WHERE Emp_No=100
UPDATE @result SET name ='ChitharanPraveen'
RETURN
END

---Execution-------
SELECT *FROM Employeetablevaluefunction1(100)
SELECT *FROM EmployeeOfficial

Wednesday, August 3, 2011

An Overview of Silverlight

Silverlight enables development of the next generation of Microsoft .NET-based media experiences and rich interactive applications (RIAs) for the Web. Silverlight is delivered as a cross-platform and cross-browser plug-in that exposes a programming framework and features that are a subset of the .NET Framework and Windows Presentation Foundation (WPF).

Support

The industry has been abuzz about Silverlight since the beginning of 2007 when Microsoft began demonstrating its power at developer conferences. In fact, no other development technology has been so highly anticipated since the arrival of the .NET Framework and Silverlight resources and examples abound on the Web. To spark developer interest in Silverlight, Microsoft launched several community Web sites dedicated to Silverlight development including the Silverlight home page (http://www.microsoft.com/silverlight) and the Silverlight.net community Web site (http://silverlight.net).

Early Adopters

In response to the overwhelming developer community anticipation for the arrival of Silverlight, many developers and companies have become early adopters of the technology.
Some example sites are listed below:
  • World Series of Poker
  • Discovery Channel
  • The Emmys
  • Home Shopping Network (HSN)
  • World Wrestling Entertainment (WWE)
  • Fox
  • XBOX 360
  • Netflix - uses Silverlight to allow subscribers to instantly watch movies on their PCs or Intel-based Macs.
Many of the published early adopter applications are featured in the Silverlight.net showcase.

The .NET Framework

Microsoft introduced the .NET Framework in 2000 as a new approach to software development. The .NET Framework borrowed ideas from the best practices in the software industry as well as brought new ideas to the table in an effort to meet developer needs and requests.
Virtually all programming languages manage data at some point. The primary reason that communication between applications created using C++, Visual Basic, Visual FoxPro, and other languages was difficult was because each language stored data being managed in a unique set of data types. For example, an integer in one language may not represent an integer in another language. Data needed to be converted to common data types to communicate between languages.
The .NET Framework introduced a common set of data types (the Common Type System) that is used by all .NET-compliant languages (C++, Visual Basic, C#, etc). Thus all languages can easily intercommunicate. Furthermore, all .NET-compliant languages render a common result when compiling code, Microsoft Intermediate Language (MSIL). (see footnote) MSIL can be deployed to any platform running the Common Language Runtime (CLR). Currently, the CLR is only available for Microsoft Windows although an open source version of the CLR was created for Linux (called the Mono Project). Code written by using the .NET Framework is compiled instead of interpreted resulting in much better performance than Java and competing technologies.
Microsoft took the Web development industry by storm with their .NET upgrade to ASP. ASP.NET put a new face on Web development through a compiled code architecture and improved state management and it provides access to the full functionality of the .NET Framework. ASP.NET is built around XML, supports the latest Web development standards, and allows for the creation of advanced Web Services.
The .NET Framework also provides improved data access and database integration through ADO.NET. For more information, see MSDN.
There are many more features and benefits of the .NET Framework than those mentioned here. The .NET Framework has become the leading software development environment available.

Introducing Silverlight

What's New in the .NET Framework

As of the writing of this course, version 3.5 of the .NET Framework has been released. Version 3.5 includes features that encompass all facets of Windows, Web, and network development:
  • Includes just under 10,000 classes, methods, and properties.
  • Complies with the latest Web development standards.
  • Introduces revolutionary technologies used in Windows Vista development, rich media and user experiences, workflow management, security and authorization, and complete distributed communication protocols.
The .NET Framework can also be fully extended by developers to create custom classes and types. The functionality of the .NET Framework spans the server, the workstation, and the Web. The four primary additions to the .NET Framework as of version 3.0 are:
  1. Windows Presentation Foundation (WPF)
  2. Windows Communication Foundation (WCF)
  3. Windows Workflow Foundation (WF)
  4. CardSpace

Windows Presentation Foundation (WPF)

WPF is used to develop elaborate user interfaces like those that adorn Windows Vista and managed advanced media streaming and integration. WPF is the a complete revamp of Windows Forms so that user interface, graphic, and media development is now designed around the .NET Framework.

Windows Communication Foundation (WCF)

WCF encompasses the ASP.NET Web Services and .NET remoting functionality that was contained in the .NET Framework 2.0 as well as new communication technologies.

Windows Workflow Foundation (WF)

WF is used to model complex workflow processes.

CardSpace

CardSpace is the embodiment of new security and user authorization functionality.

ASP.NET AJAX

ASP.NET AJAX was developed to improve performance in the browser by making post backs and calls between the browser and server asynchronously. ASP.NET AJAX uses new built-in types and controls and JavaScript.
Both ASP.NET and ASP.NET AJAX are heavily dependent upon the ASP.NET page event life cycle, are tightly coupled to the server, and have a tough time competing with advanced, media-rich plug-in solutions such as Adobe Flash. Additionally, it is difficult to create Web applications that offer a consistent experience across all supported browsers and platforms by using ASP.NET and AJAX. In 2006, Microsoft began developing a solution to extend into the browser and offer media experiences more robust than competing plug-in solutions.
In 2007, Microsoft introduced Silverlight. (see footnote) Silverlight is a free plug-in that encompasses a subset of functionality from the .NET Framework and WPF. In a manner similar to the JVM (see footnote), Silverlight runs in the browser as a "sandbox" - a secure zone installed into the browser that accommodates Silverlight functionality while completely protecting the host platform from any possibly adverse actions performed by Silverlight.

Silverlight Architecture

Unlike ASP.NET, the bulk of Silverlight processing occurs on the client machine thus decreasing server resource utilization and improving the Web experience on the client. The figure below shows the difference between ASP.NET processing and Silverlight processing:
When a client initially attempts to run a Silverlight application, if the Silverlight plug-in has not been installed on the client machine, it will be downloaded and installed. Upon subsequent requests to run the application, the application will instantiate on the client machine and make requests for resources from the server only when necessary. The Silverlight plug-in can be thought of as a scaled-down version of the full .NET Framework. It only contains those classes and functionality that are applicable to a Silverlight Web client and those were streamlined and optimized for use on the Web client machine.
Silverlight was designed using the same design paradigm as ASP.NET. Each page of a Silverlight application includes an associated code behind file that includes the code that handles events fired by the page. Silverlight resembles WPF in that it uses Extensible Application Markup Language (XAML) to construct the user interface (presentation layer). As Silverlight applications are composed of text-based files that include markup and code, they can be created using any text editor; however, more advanced tools and development environments such as Visual Studio or Expression Blend simplify the task significantly.

Silverlight Technologies

Version 1.0 of Silverlight used JavaScript and supported the industry-leading Windows Media Services enabling delivery of audio and video that includes 2D and vector graphics.
Version 2 includes all features of version 1.0 and:
  • support for the .NET Framework.
  • support for .NET-compliant programming languages such as C#, Visual Basic, Python, and Ruby.
  • support for database operations and language-integrated query (LINQ).
The figure below illustrates the major differences between version 1.0 and version 2:
The diagram located at ClassFiles/WhatIsSilverlight/Demos/SilverlightTechnologyMap.gif gives a broad picture of the technologies to be supported by Silverlight version 2.

Silverlight Hosting

Microsoft Silverlight functionality is completely encapsulated within the Silverlight plug-in. Web applications typically require the server hosting the Web application to meet minimum requirements. Silverlight applications simply require a Web server to be equipped as they would be for hosting HTML documents. Silverlight applications can be hosted on any Web server accessible to the target audience. The two most commonly used Web servers are Microsoft Internet Information Server (IIS) and Apache.
Executing a Silverlight application on a Web client machine is a two step process. First, the application will detect if the Silverlight plug-in is installed on the Web client machine. If the plug-in is not installed, the user will be prompted with an option to download the plug-in. If the user opts to do so, a request will be made of the Web server to download and install the plug-in. The Silverlight plug-in is embodied in a .dll executable file that is loaded into the Web client browser memory once installed. The only interaction required by the Web client when installing the Silverlight plug-in is to grant permission for the plug-in to be installed. Various Web servers, including Microsoft Internet Information Server (IIS), may require slight configuration modifications so that the Silverlight executable file will be downloaded to the Web client when requested.
Second, once the Silverlight plug-in is installed on the Web client machine, the Silverlight application itself must be downloaded. A Silverlight application may consist of many types of files. Slight configuration modifications may be necessary on the Web server, such as MIME types, so that XAML and XAP files are associated with Silverlight and downloaded correctly to the Web client machine when requested.
Once the Silverlight plug-in is installed on a Web client machine and a Silverlight application is downloaded, the Silverlight application is then hosted on the Web client machine. There are some requirements necessary for the Web client machine as discussed in the sections below, however all media players, audio and video codecs, compilers and the runtime are encapsulated in the Silverlight plug-in.

Supported Platforms

Silverlight can be installed on Windows and Macintosh machines. Silverlight applications run within the confines of a plug-in. There are many benefits to using a plug-in with the primary benefit being consistency across implementations. A plug-in application can provide a consistent result in every instance where it is supported. Other plug-in solutions, such as Adobe Flash, have become popular due to consistency across implementations. For instance, a plug-in application should deliver a consistent result regardless of whether it is displayed using Internet Explorer on Windows or Safari on a Macintosh.
Silverlight 2 is currently supported on the platforms discussed below. (see footnote)
Platforms that Support Silverlight 2
Operating System Browser
  • Windows Vista
  • Windows XP SP2
  • Windows 2000
  • Windows Server 2003
  • Internet Explorer 7+
  • Firefox 1.5+
  • Google Chrome
  • Macintosh OS 10.4.8+ (Intel Based)
  • Safari
  • Firefox 1.5+

Linux

Many developers are unaware that a version of the .NET Framework exists for the Linux operating system. Linux is an open source operating system that is supported heavily in the online community. The version of the .NET Framework that supports Linux is named the Mono project and was also developed by the open source community. The developers of the Mono project keep the project close to in sync with the .NET Framework when updates are released by Microsoft and created an initial, limited version of Silverlight (called "Moonlight") that supports Linux in approximately 21 days! (see footnote) You can get up to date information on this project at http://www.mono-project.com/Moonlight.

Future Platforms

The Silverlight plug-in renders graphics and multimedia using a vector-based graphics engine. Vector graphics can easily be scaled from very small displays to very large displays of varying resolutions with virtually no loss of image quality. Silverlight on a Windows Mobile device will accommodate delivering live, streaming, high quality video to smart phones and similar devices. The goal is to enable developers to deliver rich interactive applications (RIA) to any type of device.
Microsoft has announced support for Silverlight on mobile devices with a limited initial support for Windows Mobile and the Nokia S60 models. You can learn more about this future support at http://www.microsoft.com/silverlight/overview/mobile.aspx.