Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it a programmatic way to get SQL keywords (reserved words)
    primarykey
    data
    text
    <p>I need to validate the <strong>Name</strong> of a SQL column, which is created programmatically...</p> <p>There whould be 2 validation rules: </p> <ol> <li>The <strong>Name</strong> shouldn't be a C# keyword</li> <li>The <strong>Name</strong> shouldn't be a SQL keyword <em>(SQL Server 2008 R2)</em></li> </ol> <hr> <p><strong>The solution for 1st rule it's nice:</strong> </p> <p>The <strong>CSharpCodeProvider</strong> class has the <strong>IsValidIdentifier</strong> method which makes the implementation of validation easy. </p> <p>(ex: </p> <pre><code>string myColumnName = "blabla"; var isValid = _cSharpCodeProvider.IsValidIdentifier(myColumnName); </code></pre> <p>)</p> <hr> <p><strong>The solution for 2nd rule it's a litle verbose:</strong></p> <p>The only way I found doing google searches is to take the keywords from <a href="http://msdn.microsoft.com/en-us/library/ms189822%28v=sql.105%29.aspx" rel="nofollow">MSDN - Reserved Keywords (Transact-SQL) SQL Server 2008 R2 </a></p> <p>To build a string[] property which will return all these keywords...</p> <p>(ex:</p> <pre><code>public static class SqlReservedKeywords { public static string[] SqlServerReservedKeywords { get { return SqlServerKeywords; } } private static readonly string[] SqlServerKeywords = new[] { "ADD","EXISTS","PRECISION", //. . . "EXEC","PIVOT","WITH", "EXECUTE","PLAN","WRITETEXT" }; } </code></pre> <p>//External code</p> <pre><code>var isValid = SqlReservedKeywords.SqlServerReservedKeywords.Contains(myColumnName); </code></pre> <p>)</p> <hr> <p>Can you advice me about implementantion of 2nd validation rule. Is it a good practice? Maybe it exist another way to implement which i didn't found by googling...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload