HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Prevent Inserts without Column List

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
preventwithoutcolumninsertslist

Problem

We have a database running on SQL 2008 R2, in 2000 Compatibility mode.

Is there a way to configure the database so that implicit insert statements (i.e. those without a column list) are invalid?

I want to stop developers writing scripts like this:

Insert into foo
values (2, 3)


and instead use

Insert into foo (Val1, Val2)
values (2, 3)


especially within stored procedures, but across the board if at all possible.

Solution

No, there is no such configuration available.

Of course, you are not the only one concerned about style. You might find some posts by Alexander Kuznetsov helpful in pursuing your overall reliability goals.

One of his posts is: Developing Low-Maintenance Databases

https://www.simple-talk.com/sql/database-administration/developing-low-maintenance-databases/

He has an online book entitled: Defensive Database Programming

https://www.simple-talk.com/books/sql-books/defensive-database-programming/

But SQL Server has no 'strict checks' although Erland Sommarskog has proposed that something should be done about this. (No traction yet, though.)

http://www.sommarskog.se/strict_checks.html

So, perhaps you can create a process that examines the text of a stored procedure, but it will not be simple. And you can have rigid code review.

Context

StackExchange Database Administrators Q#102458, answer score: 3

Revisions (0)

No revisions yet.