SlideShare a Scribd company logo
1 of 7
Download to read offline
1.Difference between VARCHAR and NVARCHAR in SQL Server

     S.No   Varchar[(n)]                         NVarchar[(n)]

     1      Basic Definition:                    Basic Definition:

            Non-Unicode Variable Length          UNicode Variable Length character
            character data type.                 data type. It can store both non-
                                                 Unicode and Unicode (i.e. Japanese,
            Example:                             Korean etc) characters.
            DECLARE @FirstName AS
            VARCHAR(50) = ‘UMAR’                 Example:
            SELECT @FirstName                    DECLARE @FirstName AS
                                                 NVARCHAR(50)= ‘UMAR’
                                                 SELECT @FirstName

     2      No. of Bytes required for each       No. of Bytes required for each
            character:                           character:

            It takes 1 byte per character        It takes 2 bytes per Unicode/Non-
                                                 Unicode character.
            Example:
            DECLARE @FirstName AS                Example:
            VARCHAR(50) = ‘UMAR’                 DECLARE @FirstName AS
            SELECT @FirstName AS                 NVARCHAR(50)= ‘UMAR’
            FirstName,DATALENGTH(@Firs           SELECT @FirstName AS
            tName) AS Length                     FirstName,DATALENGTH(@FirstNa
                                                 me) AS Length
            Result:
            FirstName Length                     Result:
            UMAR 4                               FirstName Length
                                                 UMAR 8

     3      Optional Parameter n range:          Optional Parameter n range:

            Optional Parameter n value can be Optional Parameter n value can be
            from 1 to 8000.Can store          from 1 to 4000.Can store maximum
            maximum 8000 Non-Unicode          4000 Unicode/Non-Unicode characters
            characters.

     4      If Optional Parameter n is not       If Optional Parameter n is not
            specified in the variable            specified in the variable declaration
            declaration or column                or column definition:
            definition:
                                                 If Optional parameter value n is not
            If Optional parameter value is not   specified in the variable declaration or
            specified in the variable            column definition then it is considered
            declaration or column definition     as 2
            then it is considered as 1.
                                                 Example:
            Example:                             DECLARE @firstName NVARCHAR
            DECLARE @firstName                   =‘UMAR’
            VARCHAR =‘UMAR’                      SELECT @firstName
SELECT @firstName                     FirstName,DATALENGTH(@firstNa
    FirstName,DATALENGTH(@firs            me) Length
    tName) Length
                                          Result:
    Result:                               FirstName Length
    FirstName Length                      U2
    U1

5   If Optional Parameter n is not        If Optional Parameter n is not
    specified in while using              specified in while using
    CAST/CONVERT functions:               CAST/CONVERT functions:

    When this optional parameter n is     When this optional parameter n is not
    not specified while using the         specified while using the CAST
    CAST/CONVERT functions, then          CONVERT functions, then it is
    it is considered as 30.               considered as 30.

    Example:                              Example:
    DECLARE @firstName                    DECLARE @firstName
    VARCHAR(35) =‘UMAR ASIA               NVARCHAR(35) =‘UMAR ASIA
    INDIA TAMIL NADU                      INDIA TAMIL NADU
    CUDDALORE’                            CUDDALORE’
    SELECT CAST(@firstName AS             SELECT CAST(@firstName AS
    VARCHAR)                              NVARCHAR)
    FirstName,DATALENGTH(CAS              FirstName,DATALENGTH(CAST(@f
    T(@firstName AS VARCHAR))             irstName AS NVARCHAR)) Length
    Length
                                          Result:
    Result:                               FirstName Length
    FirstName Length                      UMAR ASIA INDIA TAMIL NADU
    UMAR ASIA INDIA TAMIL                 CUD 60
    NADU CUD 30


7   Which one to use?                     Which one to use?

    If we know that data to be stored     If we know that data to be stored in the
    in the column or variable doesn’t     column or variable can have Unicode
    have any Unicode characters.          characters.

8   Storage Size:                         Storage Size:

    Takes no. of bytes equal to the no.   Takes no. of bytes equal to twice the
    of Characters entered plus two        no. of Characters entered plus two
    bytes extra for defining offset.      bytes extra for defining offset.
2.Difference between SQL Server and MySQL


     S.No   SQL Server                      MySQL

     1      Current Date and Time:          Current Date and Time:

            SELECT GETDATE()                SELECT NOW()

                                            Optionally: Use CURDATE() for the
                                            date only.

     2      Limiting Results:               Limiting Results:

            SELECT TOP 10 * FROM table      SELECT * FROM table WHERE id =
            WHERE id = 1                    1 LIMIT 10

     3      Date Field Default Value:       Date Field Default Value:

            DATETIME DEFAULT                DATETIME fields cannot have a
            GETDATE()                       default value, i.e. "GETDATE()"

                                            We must use your INSERT statement
                                            to specify CURDATE() for the field.

                                            Optionally: Use datatype
                                            TIMESTAMP DEFAULT
                                            CURRENT_TIMESTAMP

     4      Character Length:               Character Length:

            LEN()                           CHARACTER_LENGTH()
                                            Aliases: CHAR_LENGTH(),
                                            LENGTH()

     5      Character Replace:              Character Replace:

            REPLACE() works case            REPLACE() works case sensitively
            insensitively

     6      Trim Functions:                 Trim Functions:

            LTRIM() and RTRIM()             TRIM()

     7      String Concatenation:           String Concatenation:

            CONCATENATION USING +           CONCAT(string, string), which
            (Does not automatically cast    accepts two or more arguments.
            operands to compatible types)   (Automatically casts values into types
                                            which can be concatenated)

     8      Auto Increment Field            Auto Increment Field Definition:
            Definition:
tablename_id INTEGER
     tablename_id INT IDENTITY         AUTO_INCREMENT PRIMARY
     PRIMARY KEY                       KEY

9    Get a List of Tables:             Get a List of Tables:

     SP_TABLES                         SHOW TABLES

10   Get Table Properties:             Get Table Properties:

     HELP tablename                    DESCRIBE tablename

11   Get Database Version:             Get Database Version:

     SELECT @@VERSION                  SELECT VERSION()

12   Recordset Paging:                 Recordset Paging:

     Recordset paging done by client   Add to end of SQL: "LIMIT " &
     side-ADO (very involved)          ((intCurrentPage-1)*intRecsPerPage)
                                       & ", " & intRecsPerPage
                                       LIMIT: The first argument specifies
                                       the offset of the first row to return, and
                                       the second specifies the maximum
                                       number of rows to return. The offset of
                                       the initial row is 0 (not 1).

13   Get ID of Newest Inserted         Get ID of Newest Inserted Record:
     Record:
                                       Two step process:
     SET NOCOUNT ON; INSERT            1. Execute your statement:
     INTO...; SELECT                   objConn.Execute("INSERT INTO...")
     id=@@IDENTITY; SET                2. Set objRS =
     NOCOUNT OFF;                      objConn.Execute("SELECT
                                       LAST_INSERT_ID() AS ID")

14   Get a Random Record:              Get a Random Record:

     SELECT TOP 1 * FROM Users         SELECT * FROM Users ORDER BY
     ORDER BY NEWID()                  RAND() LIMIT 1

15   Generate a Unique GUID:           Generate a Unique GUID:

     SELECT NEWID()                    SELECT UUID()
3.Difference between SET QUOTED_IDENTIFIER ON and SET QUOTED_IDENTIFIER
OFF in SQL Server


     S.No   SET QUOTED_IDENTIFIER              SET QUOTED_IDENTIFIER OFF
            ON

     1      Characters Enclosed within         Characters Enclosed within double
            double quotes:                     quotes:

            is treated as Identifier           is treated as Literal

     2      Try using Characters Enclosed      Try using Characters Enclosed
            within double quotes as            within double quotes as identifier:
            identifier:
                                               Fails
            Works                              Example: Below statement to create a
            Example: Below statement to        table with table name “Table” Fails.
            create a table with table name     SET QUOTED_IDENTIFIER OFF
            “Table” succeeds.                  GO
            SET QUOTED_IDENTIFIER ON           CREATE TABLE dbo.”Table”
            GO                                 (id int,”Function” VARCHAR(20))
            CREATE TABLE dbo.”Table”           GO
            (id int,”Function”                 Error Message:
            VARCHAR(20)) GO                    Msg 102, Level 15, State 1,
                                               Line 1 Incorrect syntax near ‘Table’.

     3      Try using Characters Enclosed      Try using Characters Enclosed
            within double quotes as Literal:   within double quotes as Literal:

            Fails                              Works
            Example: Below statement fails.    Example: Below Statement Works.
            SET QUOTED_IDENTIFIER ON           SET QUOTED_IDENTIFIER OFF
            GO                                 GO
            SELECT “BIRADAR”                   SELECT “UMAR”
            Error Message:
            Msg 207, Level 16, State 1,
            Line 1 Invalid column name
            ‘UMAR’.

     4      Characters Enclosed within         Characters Enclosed within single
            single quotes:                     quotes:

            is treated as Literal              is treated as Literal
            Example:                           Example:
            SET QUOTED_IDENTIFIER ON           SET QUOTED_IDENTIFIER ON
            GO                                 GO
            SELECT ‘UMAR’                      SELECT ‘UMAR’


     5      How to find all the objects        How to find all the objects which are
            which are created with SET         created with SET
QUTOED_IDENTIFIER                   QUTOED_IDENTIFIER ON/OFF:
            ON/OFF:
                                                Below Statement can be used to find
            Below Statement can be used to      all the objects created with SET
            find all the objects created with   QUTOED_IDENTIFIER setting as
            SET QUTOED_IDENTIFIER               OFF:
            setting as ON:
                                                SELECT OBJECT_NAME (object_id)
            SELECT OBJECT_NAME                  FROM sys.sql_modules WHERE
            (object_id) FROM                    uses_quoted_identifier = 0
            sys.sql_modules WHERE
            uses_quoted_identifier = 1

4.Difference between DateTime and DateTime2 DataType


     S.No   DateTime                            DateTime2[(n)]

     1      Min Value: 1753-01-01 00:00:00      Min Value: 0001-01-01 00:00:00

     2      Max Value:                          Max Value:

            9999-12-31 23:59:59.997             9999-12-31 23:59:59.9999999

     3      Storage Size:                       Storage Size:

            8 Bytes                             6 to 8 bytes

                                                Note: Parameter n is optional and if it
                                                is not specified then fractional seconds
                                                precision is 7 digit and it can be from 0
                                                to 7 digit.
                                                For fractional seconds precision <3,
                                                takes 6 bytes
                                                For fractional seconds precision 3 or 4
                                                it will take 7 bytes
                                                For fractional seconds precision >4 it
                                                will take 8 bytes

     4      Usage:                              Usage:

            Declare @now datetime               Declare @now datetime2(7)

     5      Current Date and Time               Current Date and Time function:
            function:
                                                SYSDATETIME()- It returns DB
            GetDate() – It returns DB Current   Current Date and Time of DateTime2
            Date and Time of DateTime Data      Data Type
            Type
                                                Example: SELECT SYSDATETIME()
            Example: SELECT GETDATE()           Result: 2011-09-16 13:23:18.7676720
Result: 2011-09-16 13:23:18.767

      6      +/- days:                          +/- days:

             WORKS                              FAILS – Need to use only DateAdd
             Example: DECLARE                   function
             @nowDateTime DATETIME =            Example: DECLARE
             GETDATE()                          @nowDateTime2 DATETIME2=
             SELECT @nowDateTime + 1            SYSDATETIME()
             Result: 2011-09-17 13:44:31.247    SELECT @nowDateTime2+1
                                                Result: Msg 206, Level 16, State 2,
                                                Line 2
                                                Operand type clash: datetime2 is
                                                incompatible with int

      7      Compliance:                        Compliance:

             Is not an ANSI/ISO compliant       Is an ANSI/ISO compliant

Please visit my blog @ http://onlydifferencefaqs.blogspot.in/

More Related Content

What's hot

ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARDTia Ricci
 
Wayfinder Breadcrumbs 1 1
Wayfinder Breadcrumbs 1 1Wayfinder Breadcrumbs 1 1
Wayfinder Breadcrumbs 1 1Oleh Burkhay
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Objectiveccheatsheet
ObjectiveccheatsheetObjectiveccheatsheet
Objectiveccheatsheetiderdelzo
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala MakeoverGarth Gilmour
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 jwfilesmrecedu
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 

What's hot (19)

ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARD
 
C Reference Card (Ansi) 2
C Reference Card (Ansi) 2C Reference Card (Ansi) 2
C Reference Card (Ansi) 2
 
C reference card
C reference cardC reference card
C reference card
 
javaarray
javaarrayjavaarray
javaarray
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Wayfinder Breadcrumbs 1 1
Wayfinder Breadcrumbs 1 1Wayfinder Breadcrumbs 1 1
Wayfinder Breadcrumbs 1 1
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
C++ basics
C++ basicsC++ basics
C++ basics
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Ruby_Basic
Ruby_BasicRuby_Basic
Ruby_Basic
 
Module7
Module7Module7
Module7
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Objectiveccheatsheet
ObjectiveccheatsheetObjectiveccheatsheet
Objectiveccheatsheet
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
 
C Language Unit-3
C Language Unit-3C Language Unit-3
C Language Unit-3
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 jwfiles
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Advanced Python : Decorators
Advanced Python : DecoratorsAdvanced Python : Decorators
Advanced Python : Decorators
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 

Similar to Difference between VARCHAR and NVARCHAR in SQL Server

C programming - Pointers
C programming - PointersC programming - Pointers
C programming - PointersWingston
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptxFolkAdonis
 
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips  Some hints for approa.docxCSE 220 Assignment 3 Hints and Tips  Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docxfaithxdunce63732
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyworldchannel
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programmingnmahi96
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptxJawadTanvir
 
Strings in c
Strings in cStrings in c
Strings in cvampugani
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and StringsEduardo Bergavera
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptxssuserb1a18d
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9Vince Vo
 
ABAP Programming Overview
ABAP Programming OverviewABAP Programming Overview
ABAP Programming Overviewsapdocs. info
 
Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01tabish
 
chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01tabish
 

Similar to Difference between VARCHAR and NVARCHAR in SQL Server (20)

C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips  Some hints for approa.docxCSE 220 Assignment 3 Hints and Tips  Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
pps unit 3.pptx
pps unit 3.pptxpps unit 3.pptx
pps unit 3.pptx
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Fortran 90 Basics
Fortran 90 BasicsFortran 90 Basics
Fortran 90 Basics
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Strings in c
Strings in cStrings in c
Strings in c
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Unit3 C
Unit3 C Unit3 C
Unit3 C
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
ABAP Programming Overview
ABAP Programming OverviewABAP Programming Overview
ABAP Programming Overview
 
Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01
 
chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01
 

More from Umar Ali

Difference between wcf and asp.net web api
Difference between wcf and asp.net web apiDifference between wcf and asp.net web api
Difference between wcf and asp.net web apiUmar Ali
 
Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Umar Ali
 
Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Umar Ali
 
Difference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcDifference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcUmar Ali
 
Difference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcDifference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcUmar Ali
 
ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1Umar Ali
 
Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1Umar Ali
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1Umar Ali
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1Umar Ali
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1 Umar Ali
 
How to create user friendly file hosting link sites
How to create user friendly file hosting link sitesHow to create user friendly file hosting link sites
How to create user friendly file hosting link sitesUmar Ali
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamilUmar Ali
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamilUmar Ali
 
Asp.net website usage and job trends
Asp.net website usage and job trendsAsp.net website usage and job trends
Asp.net website usage and job trendsUmar Ali
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1 Umar Ali
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1 Umar Ali
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search enginesUmar Ali
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1Umar Ali
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1Umar Ali
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1Umar Ali
 

More from Umar Ali (20)

Difference between wcf and asp.net web api
Difference between wcf and asp.net web apiDifference between wcf and asp.net web api
Difference between wcf and asp.net web api
 
Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()
 
Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4
 
Difference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcDifference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvc
 
Difference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcDifference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvc
 
ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1
 
Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1
 
How to create user friendly file hosting link sites
How to create user friendly file hosting link sitesHow to create user friendly file hosting link sites
How to create user friendly file hosting link sites
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamil
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamil
 
Asp.net website usage and job trends
Asp.net website usage and job trendsAsp.net website usage and job trends
Asp.net website usage and job trends
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search engines
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1
 

Recently uploaded

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

Difference between VARCHAR and NVARCHAR in SQL Server

  • 1. 1.Difference between VARCHAR and NVARCHAR in SQL Server S.No Varchar[(n)] NVarchar[(n)] 1 Basic Definition: Basic Definition: Non-Unicode Variable Length UNicode Variable Length character character data type. data type. It can store both non- Unicode and Unicode (i.e. Japanese, Example: Korean etc) characters. DECLARE @FirstName AS VARCHAR(50) = ‘UMAR’ Example: SELECT @FirstName DECLARE @FirstName AS NVARCHAR(50)= ‘UMAR’ SELECT @FirstName 2 No. of Bytes required for each No. of Bytes required for each character: character: It takes 1 byte per character It takes 2 bytes per Unicode/Non- Unicode character. Example: DECLARE @FirstName AS Example: VARCHAR(50) = ‘UMAR’ DECLARE @FirstName AS SELECT @FirstName AS NVARCHAR(50)= ‘UMAR’ FirstName,DATALENGTH(@Firs SELECT @FirstName AS tName) AS Length FirstName,DATALENGTH(@FirstNa me) AS Length Result: FirstName Length Result: UMAR 4 FirstName Length UMAR 8 3 Optional Parameter n range: Optional Parameter n range: Optional Parameter n value can be Optional Parameter n value can be from 1 to 8000.Can store from 1 to 4000.Can store maximum maximum 8000 Non-Unicode 4000 Unicode/Non-Unicode characters characters. 4 If Optional Parameter n is not If Optional Parameter n is not specified in the variable specified in the variable declaration declaration or column or column definition: definition: If Optional parameter value n is not If Optional parameter value is not specified in the variable declaration or specified in the variable column definition then it is considered declaration or column definition as 2 then it is considered as 1. Example: Example: DECLARE @firstName NVARCHAR DECLARE @firstName =‘UMAR’ VARCHAR =‘UMAR’ SELECT @firstName
  • 2. SELECT @firstName FirstName,DATALENGTH(@firstNa FirstName,DATALENGTH(@firs me) Length tName) Length Result: Result: FirstName Length FirstName Length U2 U1 5 If Optional Parameter n is not If Optional Parameter n is not specified in while using specified in while using CAST/CONVERT functions: CAST/CONVERT functions: When this optional parameter n is When this optional parameter n is not not specified while using the specified while using the CAST CAST/CONVERT functions, then CONVERT functions, then it is it is considered as 30. considered as 30. Example: Example: DECLARE @firstName DECLARE @firstName VARCHAR(35) =‘UMAR ASIA NVARCHAR(35) =‘UMAR ASIA INDIA TAMIL NADU INDIA TAMIL NADU CUDDALORE’ CUDDALORE’ SELECT CAST(@firstName AS SELECT CAST(@firstName AS VARCHAR) NVARCHAR) FirstName,DATALENGTH(CAS FirstName,DATALENGTH(CAST(@f T(@firstName AS VARCHAR)) irstName AS NVARCHAR)) Length Length Result: Result: FirstName Length FirstName Length UMAR ASIA INDIA TAMIL NADU UMAR ASIA INDIA TAMIL CUD 60 NADU CUD 30 7 Which one to use? Which one to use? If we know that data to be stored If we know that data to be stored in the in the column or variable doesn’t column or variable can have Unicode have any Unicode characters. characters. 8 Storage Size: Storage Size: Takes no. of bytes equal to the no. Takes no. of bytes equal to twice the of Characters entered plus two no. of Characters entered plus two bytes extra for defining offset. bytes extra for defining offset.
  • 3. 2.Difference between SQL Server and MySQL S.No SQL Server MySQL 1 Current Date and Time: Current Date and Time: SELECT GETDATE() SELECT NOW() Optionally: Use CURDATE() for the date only. 2 Limiting Results: Limiting Results: SELECT TOP 10 * FROM table SELECT * FROM table WHERE id = WHERE id = 1 1 LIMIT 10 3 Date Field Default Value: Date Field Default Value: DATETIME DEFAULT DATETIME fields cannot have a GETDATE() default value, i.e. "GETDATE()" We must use your INSERT statement to specify CURDATE() for the field. Optionally: Use datatype TIMESTAMP DEFAULT CURRENT_TIMESTAMP 4 Character Length: Character Length: LEN() CHARACTER_LENGTH() Aliases: CHAR_LENGTH(), LENGTH() 5 Character Replace: Character Replace: REPLACE() works case REPLACE() works case sensitively insensitively 6 Trim Functions: Trim Functions: LTRIM() and RTRIM() TRIM() 7 String Concatenation: String Concatenation: CONCATENATION USING + CONCAT(string, string), which (Does not automatically cast accepts two or more arguments. operands to compatible types) (Automatically casts values into types which can be concatenated) 8 Auto Increment Field Auto Increment Field Definition: Definition:
  • 4. tablename_id INTEGER tablename_id INT IDENTITY AUTO_INCREMENT PRIMARY PRIMARY KEY KEY 9 Get a List of Tables: Get a List of Tables: SP_TABLES SHOW TABLES 10 Get Table Properties: Get Table Properties: HELP tablename DESCRIBE tablename 11 Get Database Version: Get Database Version: SELECT @@VERSION SELECT VERSION() 12 Recordset Paging: Recordset Paging: Recordset paging done by client Add to end of SQL: "LIMIT " & side-ADO (very involved) ((intCurrentPage-1)*intRecsPerPage) & ", " & intRecsPerPage LIMIT: The first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1). 13 Get ID of Newest Inserted Get ID of Newest Inserted Record: Record: Two step process: SET NOCOUNT ON; INSERT 1. Execute your statement: INTO...; SELECT objConn.Execute("INSERT INTO...") id=@@IDENTITY; SET 2. Set objRS = NOCOUNT OFF; objConn.Execute("SELECT LAST_INSERT_ID() AS ID") 14 Get a Random Record: Get a Random Record: SELECT TOP 1 * FROM Users SELECT * FROM Users ORDER BY ORDER BY NEWID() RAND() LIMIT 1 15 Generate a Unique GUID: Generate a Unique GUID: SELECT NEWID() SELECT UUID()
  • 5. 3.Difference between SET QUOTED_IDENTIFIER ON and SET QUOTED_IDENTIFIER OFF in SQL Server S.No SET QUOTED_IDENTIFIER SET QUOTED_IDENTIFIER OFF ON 1 Characters Enclosed within Characters Enclosed within double double quotes: quotes: is treated as Identifier is treated as Literal 2 Try using Characters Enclosed Try using Characters Enclosed within double quotes as within double quotes as identifier: identifier: Fails Works Example: Below statement to create a Example: Below statement to table with table name “Table” Fails. create a table with table name SET QUOTED_IDENTIFIER OFF “Table” succeeds. GO SET QUOTED_IDENTIFIER ON CREATE TABLE dbo.”Table” GO (id int,”Function” VARCHAR(20)) CREATE TABLE dbo.”Table” GO (id int,”Function” Error Message: VARCHAR(20)) GO Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ‘Table’. 3 Try using Characters Enclosed Try using Characters Enclosed within double quotes as Literal: within double quotes as Literal: Fails Works Example: Below statement fails. Example: Below Statement Works. SET QUOTED_IDENTIFIER ON SET QUOTED_IDENTIFIER OFF GO GO SELECT “BIRADAR” SELECT “UMAR” Error Message: Msg 207, Level 16, State 1, Line 1 Invalid column name ‘UMAR’. 4 Characters Enclosed within Characters Enclosed within single single quotes: quotes: is treated as Literal is treated as Literal Example: Example: SET QUOTED_IDENTIFIER ON SET QUOTED_IDENTIFIER ON GO GO SELECT ‘UMAR’ SELECT ‘UMAR’ 5 How to find all the objects How to find all the objects which are which are created with SET created with SET
  • 6. QUTOED_IDENTIFIER QUTOED_IDENTIFIER ON/OFF: ON/OFF: Below Statement can be used to find Below Statement can be used to all the objects created with SET find all the objects created with QUTOED_IDENTIFIER setting as SET QUTOED_IDENTIFIER OFF: setting as ON: SELECT OBJECT_NAME (object_id) SELECT OBJECT_NAME FROM sys.sql_modules WHERE (object_id) FROM uses_quoted_identifier = 0 sys.sql_modules WHERE uses_quoted_identifier = 1 4.Difference between DateTime and DateTime2 DataType S.No DateTime DateTime2[(n)] 1 Min Value: 1753-01-01 00:00:00 Min Value: 0001-01-01 00:00:00 2 Max Value: Max Value: 9999-12-31 23:59:59.997 9999-12-31 23:59:59.9999999 3 Storage Size: Storage Size: 8 Bytes 6 to 8 bytes Note: Parameter n is optional and if it is not specified then fractional seconds precision is 7 digit and it can be from 0 to 7 digit. For fractional seconds precision <3, takes 6 bytes For fractional seconds precision 3 or 4 it will take 7 bytes For fractional seconds precision >4 it will take 8 bytes 4 Usage: Usage: Declare @now datetime Declare @now datetime2(7) 5 Current Date and Time Current Date and Time function: function: SYSDATETIME()- It returns DB GetDate() – It returns DB Current Current Date and Time of DateTime2 Date and Time of DateTime Data Data Type Type Example: SELECT SYSDATETIME() Example: SELECT GETDATE() Result: 2011-09-16 13:23:18.7676720
  • 7. Result: 2011-09-16 13:23:18.767 6 +/- days: +/- days: WORKS FAILS – Need to use only DateAdd Example: DECLARE function @nowDateTime DATETIME = Example: DECLARE GETDATE() @nowDateTime2 DATETIME2= SELECT @nowDateTime + 1 SYSDATETIME() Result: 2011-09-17 13:44:31.247 SELECT @nowDateTime2+1 Result: Msg 206, Level 16, State 2, Line 2 Operand type clash: datetime2 is incompatible with int 7 Compliance: Compliance: Is not an ANSI/ISO compliant Is an ANSI/ISO compliant Please visit my blog @ http://onlydifferencefaqs.blogspot.in/