In most DBMSs (including SQLite), we can create indexes to improve query performance by allowing faster access to data. However, you might occasionally need to rename an index for whatever reason, be it for clarity, consistency, organizational purposes, or some other reason.
Continue readingTag: how to
How to Delete an Index in SQLite
If you’ve got an index in a SQLite database that you no longer need, you should probably get rid of it. Keeping unused indexes can be a drag on database performance, especially if your data is being regularly updated.
This article shows you how to delete an index in SQLite.
Continue readingList All Prepared Statements in a PostgreSQL Session
Prepared statements are a precompiled SQL queries that we can execute multiple times with different arguments. They are limited to the current session, so we can only create them and run them from within the same session.
Sometimes we might want to review how many prepared statements we’ve created. Or we might need to deallocate one, but we’ve forgotten its name.
No problem. We can use the pg_prepared_statements
view to see all of our prepared statements.
Create a DEFAULT Constraint in MySQL
In MySQL, a DEFAULT
constraint is used to provide a default value for a column when no value is specified during an INSERT
operation. This is particularly useful for ensuring that important columns have consistent, non-null values, even when omitted from inserts.
In this article, we’ll use MySQL to create a table with a couple of DEFAULT
constraints, and we’ll also add a constraint to that table after it has been created.
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 readingHow to Create an Index in SQLite
In database management systems (DBMSs) such as SQLite, indexes can be used to optimize the performance of queries, especially for larger datasets where querying can become time-consuming. An index allows the database to locate rows more quickly without scanning every row in a table.
This article explains how to create an index in SQLite, along with a simple example.
Continue readingGet the IDENTITY Values that were Generated by an INSERT Statement in SQL Server
The good thing about having IDENTITY
columns in SQL Server is that they automatically generate a unique value for every row that’s inserted into a table. This saves us from having to insert our own unique values, and I’m not going to complain about that.
But obvious question you might ask; What if I need to know the value that was generated for each column I just inserted?
Fortunately, the solution may be easier than you think!
Continue readingFix 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 readingFixing 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 readingList All Prepared Statements in MySQL
MySQL provides us with the ability to create server-side prepared statements, which are precompiled SQL queries that can be executed multiple times with different arguments.
We can use the performance schema to return a list of all prepared statements in the server, along with useful information about each prepared statement.
Continue reading