Varchar is variable length character data type which is used to store Non-Unicode data format. You can think of Non-Unicode as English characters.
NVarchar is also variable length character data type which is used to store UniCode data format. For Unicode data formats you can think of alphabets of Chinese, Japanese, Korean and Arabic language.
Varchar can stored 'English' characters and it take one byte to store each character. Nvarchar can store English and other languages characters. NVarchar take two bytes to store each character.
Let's create two variables and check the space used by each variable.
As we have declare @Variable2 as NVarchar, it took twice the space as compared to @Variable1 which is Varchar to store the characters.
Let's create a table with Varchar and NVarchar Data type columns and insert few records.
Our first Select query returned us the data. Noticed that we have some garbage data ????. Even we have defined the data type of column NVarchar, it inserted the garbage. To insert Unicode data in Nvarchar type column, we need to Use N with data as you can see in second insert ( ('عامر',N'عامر')).
NVarchar is also variable length character data type which is used to store UniCode data format. For Unicode data formats you can think of alphabets of Chinese, Japanese, Korean and Arabic language.
Varchar can stored 'English' characters and it take one byte to store each character. Nvarchar can store English and other languages characters. NVarchar take two bytes to store each character.
Let's create two variables and check the space used by each variable.
Declare @Variable1 VARCHAR(20)
Declare @Variable2 NVARCHAR(20)
SET @Variable1='TechBrothersIT'
SET @Variable2='TechBrothersIT'
Select datalength(@Variable1) as VarLength1, datalength(@Variable2) as VarLength2
What is the difference between VARCHAR and NVARCHAR - SQL Server Tutorial
As we have declare @Variable2 as NVarchar, it took twice the space as compared to @Variable1 which is Varchar to store the characters.
Let's create a table with Varchar and NVarchar Data type columns and insert few records.
Create table dbo.VarcharVsNvarchar( VarcharName Varchar(50),NVarcharName NVARCHAR(50))
insert into dbo.VarcharVsNvarchar Values
('عامر','عامر'),
('عامر',N'عامر'),
('TechBrothersIT',N'TechBrothersIT')
Select * from dbo.VarcharVsNvarchar
go
Select DataLength(VarcharName) AS CHARNameLength,DataLength(NVarcharName) AS VarNameLength
From dbo.VarcharVsNvarchar
Varchar VS Nvarchar in SQL Server - TSQL Tutorial
Our first Select query returned us the data. Noticed that we have some garbage data ????. Even we have defined the data type of column NVarchar, it inserted the garbage. To insert Unicode data in Nvarchar type column, we need to Use N with data as you can see in second insert ( ('عامر',N'عامر')).
Wow,great information. I am sure the info on your blog will help others,Thanks.
ReplyDeleteSpring Training in Chennai
Spring Training in Adyar
Spring Training in Velachery
Hibernate Training in Chennai
Hibernate Training
Spring Hibernate Training in Chennai
Spring Training in Tambaram
Spring Hibernate Training
Nice information, thanks for sharing this information.
ReplyDeleteSEO training in Chandigarh
Graphic designing course in Chandigarh
Great post, thanks for sharing important information. Software Testing Training in Pune
ReplyDeleteWell written blog.
ReplyDeleteThanks for sharing this.
Cyber security courses provided in Hyderabad are:
Artificial Intelligence Training
Ethical Hacking Training
CEH Training
Bug Bounty Training
Appreciate your knowledge in SQL Server. Indeed very helpful in understanding concepts
ReplyDeleteSoc Analyst training
Splunk Admin training
Appreciate your talent and knowledge in SQL Server. I am a web development mentor. This is so useful. Hope you will also like my website-- best data science online course certification unified mentor
ReplyDeletebiolife promotions 2023 is a platform that is aimed to help people in need. It is a medium between donors and recipients where donors give their plasma to the company.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteReally enjoyed reading this blog post! The content was informative and engaging, and the writing style was fantastic.
ReplyDeleteVisit: AWS Certified Security Specialty Exam Preparation in Pune
ReplyDeleteAre your emails truly secure? Discover how <a href='https://cyberguard.ae/libraesva/ >Libraesva Email Security Gateway</a> protects your organization's communications from all threats.
ReplyDeleteNeed zoho authorized partner ? Visit our sites : https://www.techtronserv.com/zoho-sign-up
very informative article. Python Course In Pune
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat explanation of the differences between VARCHAR and NVARCHAR! For those interested in cybersecurity, Indian Cyber Security Solutions offers comprehensive CEH Training in Hyderabad. It's a fantastic opportunity to gain ethical hacking skills and advance your career. Learn more here: CEH Training in Hyderabad.
ReplyDeletehttps://indiancybersecuritysolutions.com/ceh-training-in-hyderabad/