Nvarchar/Nchar Columns with Default Values

  • We are looking at converting all columns within a database to nvarchar & nchar from varchar & char. I've been able to do the conversion but I have question about when we use default values on a nvarchar column do we have to till SQL that it a Unicode string like when you execute a stored proc with a nvarchar Para.

    Execute with Nvarchar

    exec dbo.sptest N'testing'

    Execute with varchar

    exec dbo.sptest 'testing'

    so it this same with default values on nvarchar columns or does SQL kwon that the string is going to be a Unicode string.

    CREATE TABLE [dbo].[tbl_test]

    (col1 NVARCHAR(50) NOT NULL )

    ALTER TABLE [dbo].[tbl_test] ADD CONSTRAINT [DF_tbl_test_Col] DEFAULT ('Unknown') FOR [Col1]

    OR

    ALTER TABLE [dbo].[tbl_test] ADD CONSTRAINT [DF_tbl_test_Col] DEFAULT (N'Unknown') FOR [Col1]

     

  • If you can be explicit, be explicit. Otherwise SQL may have to do an implict conversion (which adds overhead).

    Be sure to check and make sure you do not have any VARCHAR or CHAR columns that are more than 4000 characters wide.

    SQL guy and Houston Magician

  • Ya and also you'll have to check all your input parameters and variables in the code to avoid implicit conversions.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply