Solved

Determine the length of the longest string in a CSV file to figure out the optimal "x" for an NVARCHAR(x)

Posted on 2008-10-03
2
767 Views
Last Modified: 2013-11-25
Hi,

I want to know the best way to see, for each column in a CSV file, what the longest string is in the column. This way we can pick a number of characters that is 20% larger than this for a cushion. I know i could just use an nvarchar(max), but I think this is needlessly wasteful. I know I could do something like this in excel, but I think the best solution would be a little command/script I could run in Powershell or something.

Thanks!
0
Comment
Question by:Dicklestein
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 50 total points
ID: 22634961
The great thing about nvarchar fields is the VAR.  It's variable.  The actual space used is limited to the actual data on each row.  nvarchar(max) will also stay in the the page if possible.  Only if the data is too big to fit on a page will it not be stored with it.
0
 

Author Comment

by:Dicklestein
ID: 22636986
OK, I understand. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now