Home > Back-end >  How to get SQL Server variable limit in C#
How to get SQL Server variable limit in C#

Time:06-15

I have a SQL Server table Workers and it has a column Name which is of datatype nvarchar(20).

I am using an ADO.NET Entity Data Model.

In my project, I want to limit user input to 20 characters (limit of my Name column).

How can I get this data through C# code and use it?

CodePudding user response:

All this information is stored in the SQL Server system catalog views in the sys schema.

You can e.g. get the max length of a particular column like this:

SELECT
    c.Name, c.max_length
FROM
    sys.columns c
INNER JOIN
    sys.tables t ON t.object_id = c.object_id
WHERE
    t.Name = 'Workers'
    AND c.Name = 'Name'

CodePudding user response:

Value is a reserved SQL word,so add [] to it.

  • Related