GUID in Sql server part - 2

Let us consider the following table.


Create Database infosysdb
Go

Use infosysdb
Go

Create Table Infosysemployees1
(
     ID uniqueidentifier primary key default NEWID(),
     Name nvarchar(100)
)
Go

Insert Into Infosysemployees1 Values (default,'sai')
Insert Into Infosysemployees1 Values (default,'kalyan')

Now select the data from the Infosysemployees1 table as follows.

Select * From infosysdb.dbo.Infosysemployees1


Now create another table as follows.

Create Database wipro
Go

Use wipro
Go

Create Table wiproemployees1
(
     ID uniqueidentifier primary key default NEWID(),
     Name nvarchar(100)
)
Go

Insert Into wiproemployees1 Values (default,'vijendhar')
Insert Into wiproemployees1 Values (default,'sundeep')

Now select the data from wiproemployees1 table as follows.


Select * From wipro.dbo.wiproemployees1


Now create another table to consolidate above two tables data.


Create Database wipro
Go

create table employees1
(
id uniqueidentifier primary key, name varchar(100)
)

insert into employees1
Select * From wipro.dbo.wiproemployees1
union all

Select * From infosysdb.dbo.Infosysemployees1

Now select the data from employees1 table as follows.

select * from employees1

So when we performed union all with the identity we got an error in this way. The GUID is globally unique across the tables, databases, servers.


Note:

The GUID is the large data type in SQL server.
GUID size is 16 bytes, where as INT size is 4 byes.
It's really hard to read when compared to INT.




                                         GUID IN SQL SERVER PART - 1


No comments:

Post a Comment

What is Normalization?

Database normalization is a data design and organization process applied to data structures based on rules that help building relational dat...