Anup Shah on WPF and Silverlight (Programming Garden)

IT 's For You!!!

Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Thursday, January 9, 2020

What is SSIS package in SQL Server?

6:04 PM
SSIS

SQL Server Integration Services (SSIS) is a tool that we use to perform ETL operations that are extracted, transform and load data.  ETL operations are very common in data warehousing (DW) applications, SSIS is by no means limited to just data warehousing; 
SQL Server Integration Services basics usages,
  • To retrieve data from just about any source (file, database, etc.)
  • To perform various transformations on the data; e.g. convert from one type to another, convert to u, ppercase or lowercase, perform calculations, etc.
  • To load data into just about any source
  • To define a workflow
The first version of SSIS was released with SQL Server 2005.  SSIS is a replacement for Data Transformation Services (DTS) which was available with SQL Server 7.0 and SQL Server 2000.  SSIS builds on the capabilities introduced with DTS.
In this tutorial, we will step through a number of topics that you need to understand in order to successfully build an SSIS package.  Our high-level outline is as follows:
  • Creating SSIS packages with SQL Server Management Studio (SSMS)
  • Business Intelligence Development Studio (BIDS)
  • Creating a simple SSIS package in BIDS
  • Deploying SSIS packages
  • Executing SSIS packages
You can either use the outline on the left or click the arrows to the right or below to scroll through each of these topics.

Wednesday, April 16, 2014

Difference between inner join and equi join and natural join

4:20 PM

Inner Join

This is the most used join in the SQL. this join returns only those records/rows that match/exists in both the database tables.

Inner Join Example

  
  1. SELECT * FROM tblEmp JOIN tblDept
  2. ON tblEmp.DeptID = tblDept.DeptID;
Inner Join Result
tblEmp.Name
tblEmp.DeptID
tblDept.Name
tblDept.DeptID
Hitesh
1
HR
1
Ankit
2
IT
2
Miki
2
IT
2
Anup
3
ADMIN
3
In the join condition, you can also use other operators like <,>,<>.

Equi Join

Equi join is a special type of join in which we use only equality operator. Hence, when you make a query for join using equality operator then that join query comes under Equi join.

Equi Join Example

  
  1. SELECT * FROM tblEmp JOIN tblDept
  2. ON tblEmp.DeptID = tblDept.DeptID;
  3. --Using Clause is not supported by SQL Server
  4. --Oracle and MySQL Query
  5. SELECT * FROM tblEmp INNER JOIN tblDept USING(DeptID)
Equi Join Result
tblEmp.Name
tblEmp.DeptID
tblDept.Name
tblDept.DeptID
Hitesh
1
HR
1
Ankit
2
IT
2
Miki
2
IT
2
Anup
3
ADMIN
3

Note

  1. Inner join can have equality (=) and other operators (like <,>,<>) in the join condition.
  2. Equi join only have equality (=) operator in the join condition.
  3. Equi join can be an Inner join, Left Outer join, Right Outer join
  4. The USING clause is not supported by SQL Server and Sybase. This clause is supported by Oracle and MySQL.

Natural Join

Natural join is a type of equi join which occurs implicitly by comparing all the same names columns in both tables. The join result have only one column for each pair of equally named columns.

Natural Join Example

  
  1. --Run in Oracle and MySQL
  2. SELECT * FROM tblEmp NATURAL JOIN tblDept
Natural Join Result
DeptID
tblEmp.Name
tblDept.Name
1
Hitesh
HR
2
Ankit
IT
2
Miki
IT
3
Anup
ADMIN
In the above join result we have only one column "DeptID" for each pair of equally named columns.

Note

  1. In Natural join, you can't see what columns from both the tables will be used in the join. In Natural join, you might not get the desired result what you are expecting.
  2. Natural join clause is not supported by SQL Server, it is supported by Oracle and MySQL.

--
Thank you.

Kind Regards,
Anup Shah.
Mobile : +91 8460372171 
Skype  : anupshah.india | gtalk: anupshah2it

​​

Monday, December 31, 2012

Difference between Truncate and Delete

12:42 PM
i) Truncate an Delete both are used to delete data from the table.
ii) These both the command will only delete the data of the specified table, they cannot remove the whole table data along with its structure both the SQL statements are used to only delete the data from the table but they both differ from each other in many aspects like syntax, performance, resources uses etc.
So, first let’s take a look of both of these terms (Truncate and Delete),


Truncate
-> Truncate command in SQL removes all rows from a table without logging the individual row deletion in the transaction log.
-> Truncate statement having the sane functionality as the Delete command has that is it deletes the data from the table without modifying or deleting the structure of the table.
-> You can not use the Where Clause with this (Truncate) statement.

Syntax:
TRUNCATE TABLE [ { database_name.[ schema_name ]. | schema_name . } ] table_name Table_name : Is the name of the table to truncate or from which all rows are removed.
Simple it looks like below query.
TRUNCATE TABLE Employees
The above command will delete all data from the table Employees.




Delete
-> Delete command in SQL also removes all rows from a table with logging the individual row deletion in the transaction log.
-> You can use the Where Clause with this (Delete) statement.
-> For more focus please follow the link Click me

Syntax:
DELETE FROM TABLE_NAME[ { database_name.[ schema_name ]. | schema_name . } ] table_name Table_name : Is the name of the table to truncate or from which all rows are removed.
Simple it looks like below query.
DELETE FROM Employees
The above command will delete all data from the table Employees.
In case of delete statements you can limit your delete query using where clause to delete, only particular records that fulfills the condition of where clause will be deleted not the all records.
It looks like below query with where clause.
DELETE FROM Employees Where EmployeeID IN (1,2,3)


Happy Coding!!! 

Thursday, December 13, 2012

SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server.

4:17 PM

These are the common questions, How to import CSV file into SQL Server? How to load CSV file into SQL Server Database Table? How to load comma delimited file into SQL Server? 
Let us see the solution here
CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values.

1) Create a Table using the below script: (To Download Please Click Here)

USE [Experimental]
GO
/****** Object:  Table [dbo].[CSVTest]    Script Date: 12/13/2012 16:08:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[CSVTest](
[ID] [int] NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BirthDate] [smalldatetime] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF





2) Create CSV file in drive e: with name csvtest.txt with following content. The location of the file is E:\csvtest.txt (To Download Please Click Here)
1, Anup, Shah, 19880803
2, Mac, Macwan, 19880803
3, Ankit, Patel, 19880803
4, Devang, Shah, 19880803

3) Now run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted. 
BULK
INSERT CSVTestFROM 'E:\csvtest.txt' WITH
(
FIELDTERMINATOR ',',

ROWTERMINATOR '\n')
GO
--Check the content of the table.
SELECT FROM CSVTest
GO









Converting SQL Server Database to XML format

3:55 PM

i. First Open Notepad and write below code till </root>:

<root>
<%begindetail%>
<%insert_data_here%>
<%enddetail%>
</root>

Now Save it as c:\sqlexamples\template.tpl

Next you open SQL Server Query Editor and type:

sp_makewebtask @outputfile = 'c:\myxmlfile.xml',
    @query = 'select * from sysobjects for xml auto',
    @templatefile = 'c:\sqlexamples\template.tpl'

The Result is a XML-File!

Happy Coding! ;)

Tuesday, October 23, 2012

What is the difference between transaction and query?

7:44 PM

QUERY:
A query is a single SQL statement that does Select, Update, Insert or Delete of rows.


Transaction:
A transaction is a consecutive sequence of SQL statements (from the application viewpoint) that have the "ACID" properties:
  • Atomicity: All statements or none are executed.
  • Consistency: Data integrity is always maintained.
  • Isolation: Transaction A can never affect Transaction B.
  • Durability: Changes that are committed by a transaction persist, even in event of system failure.

Monday, July 9, 2012

SQL SERVER – 2005 List All Tables of Database

5:47 PM

This is very simple and can be achieved using system table sys.tables.
USE YourDBName
GO 

SELECT 
*FROM sys.Tables
GO
This will return all the tables in the database which user have created.