get insert script withou prefix N' in sql

harinathu 6 Reputation points
2022-12-10T06:24:44.617+00:00

Hi I have one doubt in sql server
how to take data backup withou prefix N' in each filed value before .

database ...>tasks ..>generate scripts...>next ...>
select specific database objects...>choose table..>next..> open new querywindow..>
advanced ..>type of datatoscript..>schema only...next
and insert script getting like below ;
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (1, N'abc', 10.0000, N'unknowN')
GO
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (2, N'unknown', 20.0000, N'che')
GO
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (3, N'nkiln', 89.0000, N'nl')
GO
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (4, N'ravin', 0.0000, N'nrN')
GO

I want insert script with out prefix N' value like below :
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (1, 'abc', 10.0000, 'unknowN')
GO
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (2, 'unknown', 20.0000, 'che')
GO
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (3, 'nkiln', 89.0000, 'nl')
GO
INSERT [dbo].[emp] ([id], [name], [sal], [loc]) VALUES (4, N'ravin', 0.0000, N'nrN')
GO

please tell me any setting need and how to take insert scripts backup without prefix N' .

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-12-10T10:08:58.14+00:00

    To backup a database, use the BACKUP command.

    Scripting a table is not a backup. It may be useful for other purposes, but a backup it ain't.

    What it is the reason you don't want to include the N prefix? For an nvarchar column with data outside the code page, this could lead to data loss.

    If the intention is to use the script on a platform that does not recognise the N prefix I am somewhat surprised, as the N is part of the ANSI standard, as far as I know.

    In any case, SSMS does not any offer any option to leave out the N. You would have to employ your regular expression skills in a text editor to remove the N. The search pattern would be something like ([\(,]\s*)N') and the replace pattern would be \1'. The exact formation of the RE depends on the RE engine in editor. (And there is a faint possibility that you get some false positives and removes an N at the end of a character literal.)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.