I'm attempting to write a check constraint on an NVARCHAR(MAX)
column in my database. This column will be filled with SQL, and I want to make sure that it is only populated with SQL. Is it possible to write a check constraint to make sure that this column is only populated with SQL?
Asked
Active
Viewed 78 times
0

Wpowell
- 31
- 3
-
2The best way to verify the validity of SQL is to not reinvent mechanisms that the database already has for storing SQL - e.g. views, stored procedures, etc. – Damien_The_Unbeliever Sep 21 '20 at 15:36
-
The only way to manipulate data in a table is to use SQL (insert, update, delete). So "*that it is only populated with SQL*" makes no sense, as there is no other way to do it. – Sep 21 '20 at 18:26
1 Answers
0
Sounds like what you're essentially looking for is language detection - instead of using it to filter things out (e.g., like mail clients who tell you things like "OMG THIS IS CODE DO NOT CLICK ON THE ATTACHMENT"), you want to filter things in. There's a similar thread here with an excellent answer by @Michael Myers. A helpful soul (@nisc) also linked to how Github does lang detection here.

Bobbie Conti
- 36
- 2