Fix Error “AUTOINCREMENT not allowed on WITHOUT ROWID tables” in SQLite

If you’re getting an error that reads “AUTOINCREMENT not allowed on WITHOUT ROWID tables” in SQLite, it appears that you’re trying to define a column as an AUTOINCREMENT in a WITHOUT ROWID table.

SQLite doesn’t allow us to create AUTOINCREMENT columns on WITHOUT ROWID tables.

To address this issue, either remove the AUTOINCREMENT attribute or remove the WITHOUT ROWID from the table definition.

Continue reading

Fix Error: unknown datatype for (columnname): “DATE” in SQLite

If you’re getting an error that reads something like “unknown datatype for (columnname): “DATE”” in SQLite, it appears that you’re trying to define a column as a DATE type in a strict table.

SQLite doesn’t support the DATE type, however, this error should only occur on strict tables (i.e. a table defined as STRICT).

To fix this issue, either use a supported data type or make the table a regular (non-strict) table.

Continue reading

Fix “Violation of PRIMARY KEY constraint” in SQL Server (Error 2627)

If you’re getting an error that reads something like “Violation of PRIMARY KEY constraint ‘PK_CatId’. Cannot insert duplicate key in object ‘dbo.Cats’. The duplicate key value is (1)” in SQL Server, it’s because you’re trying to insert a duplicate value into a primary key column.

A primary key cannot contain duplicate values.

To fix this issue, you’ll need to change the value you’re trying to insert into the primary key column.

Continue reading

Fix Error 137 “Must declare the scalar variable” in SQL Server

If you’re getting SQL Server error 137 that goes something like “Must declare the scalar variable…“, it’s probably because you’re referring to a variable that hasn’t been declared.

If the variable has been declared, it’s possible you’re referring to it incorrectly in the code.

When we use a variable in SQL Server, we must declare the variable first.

To fix this issue, declare the variable. Also be sure to use the right syntax when using it.

Continue reading

Fixing Error 1066 When Using the HANDLER Statement in MySQL

If you’re getting MySQL error 1066 which reads something like “1066 (42000): Not unique table/alias: ‘products’” when using the HANDLER statement in MySQL, it could be that you’re trying to open a table that’s already open.

If this is the case, be sure to close the table before trying to open it again. Or simply continue working without opening the table again.

Continue reading

Fix “Column … in field list is ambiguous” in MySQL (Error 1052)

If you’re getting an error that reads something like “1052 (23000): Column ‘name’ in field list is ambiguous” in MySQL, it looks like you could be referencing a column name in a query without qualifying it with the table name.

This can happen when you perform a join between tables that use the same name for one or more columns.

To fix this issue, be sure to qualify column names with the table names when performing joins across tables.

Continue reading

Fix “Syntax ‘*’ is not allowed in schema-bound objects” in SQL Server (Error 1054)

If you’re getting an error that reads “Syntax ‘*’ is not allowed in schema-bound objects” in SQL Server, it appears that you’re using the asterisk wildcard (*) to select all columns when trying to define a schema-bound object (like a schema-bound view).

As the error message states, this is not allowed.

To fix this issue, explicitly name each column.

Continue reading

Fix “Not unique table/alias” in MySQL (Error 1066)

If you’re getting an error that reads something like “ERROR 1066 (42000): Not unique table/alias: ‘d’” in MySQL, it could be that you’re trying to assign a duplicate alias to a table. Or it could be that you’re doing a self-join without assigning table aliases.

Table names and aliases must be unique when doing queries in MySQL.

The error can also happen if you use HANDLER to open a table, but then try to open it again before closing it.

To fix this issue, be sure to use unique table aliases in your query. And if you’re using HANDLER, either close the table or continue working with it (without trying to open it again).

Continue reading

Fixing Error 4121 When Using a CTE with FOR XML in SQL Server

If you’re trying to use a common table expression (CTE) that produces XML in SQL Server, but you’re getting error 4121, which reads something like “Cannot find either column “EmployeeData” or the user-defined function or aggregate “EmployeeData.query”, or the name is ambiguous” it might be that you’re trying to query the XML in the outer query, but your CTE isn’t outputting the XML as an actual xml type.

The FOR XML result must be an xml type in order to process the result on the server.

To fix this issue, make sure the CTE outputs the result using the xml data type.

Continue reading