DacFx icon indicating copy to clipboard operation
DacFx copied to clipboard

sqlproj: Add compiler error for mismatched number of select and insert columns

Open asrichesson opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Create an empty sqlproj project. Add the following objects:

CREATE TABLE TestTable(Col1 VARCHAR(250))
GO
CREATE PROCEDURE [dbo].[BadProc]
AS
	INSERT INTO
	TestTable
	(Col1)
	SELECT 'a', 'b'

Try to deploy this project to a database and you get the error:

- The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns.

Describe the solution you'd like I would like msbuild to catch these insert/select column number mismatch errors at compile time and throw a compilation error. These types of errors are very common when using ssdt projects inside of source control. If somebody misses a line while resolving a merge conflict, they won't know it will cause an error until they try to deploy it. Catching these errors early would catch a whole class of deployment errors.

There might be cases where a column number mismatch won't result in a deployment error but I'm not aware of any. Regardless, I think msbuild should be validating this basic case with simple tables and columns.

Alternative solutions If it's not safe to always throw a compiler error, a tsql warning would be good at least.

asrichesson avatar Nov 28 '23 19:11 asrichesson