You can use the ALTER TABLE
statement to enable compression on an existing table in SQL Server.
To do this, you need to use the REBUILD WITH
option, while specifying your desired compression type.
You can use the ALTER TABLE
statement to enable compression on an existing table in SQL Server.
To do this, you need to use the REBUILD WITH
option, while specifying your desired compression type.
SQL Server has a system stored procedure called sp_estimate_data_compression_savings
, which allows you to check an object’s size and its estimated size with various levels of compression.
If the object is already compressed, you can use this procedure to estimate its size when recompressed.
Objects can be compressed by using row, page, columnstore or columnstore archive compression.
Compression can be evaluated for whole tables or parts of tables. This includes heaps, clustered indexes, nonclustered indexes, columnstore indexes, indexed views, and table and index partitions.
Continue readingSQL Server’s Database Mail has a stored procedure called sp_send_dbmail
that you can use to send emails from SQL Server.
You can use this stored procedure to send query results formatted into an HTML table.
Continue readingWhen you use the sp_send_dbmail
stored procedure to email the results of a query, the column headers are included by default.
You can include or exclude the column headers with the @query_result_header
argument. To remove the column headers, use @query_result_header = 0
.
Error message 110 is a commonly encountered error in SQL Server when inserting data into a table. The full error looks like this:
Msg 110, Level 15, State 1, Line 1 There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
This happens when you specify less columns in the INSERT
statement than the number of values that you’re trying to insert with the VALUES
clause.
This will occur if you accidentally omit one or more columns from the INSERT
statement.
You’d get a similar (but technically different) error if you tried to do the opposite – specify more columns in the INSERT
statement than you try to insert.
In SQL Server, you can create DML triggers that execute code only when a specific column is updated.
The trigger still fires, but you can test whether or not a specific column was updated, and then run code only if that column was updated.
You can do this by using the UPDATE()
function inside your trigger. This function accepts the column name as its argument. It returns a boolean.
SQL Server has a database mail option that you can use to send mail from the database server.
For example, you can get notifications when SQL Server Agent jobs finish running or fail, or when there’s a high-severity error, etc.
Continue readingIf you find yourself needing to send an email automatically upon certain events occurring in SQL Server, you can do this via a trigger.
For example, you could automatically send an email when somebody deletes or updates a record from a table, etc.
To do this, you need to create a trigger that includes code for sending the email upon the required event.
Continue readingWhen you create a trigger in SQL Server, you have the option of firing it in conjunction with the triggering statement (i.e. the SQL statement that fired the trigger), or firing it instead of that statement.
To fire the trigger instead of the triggering statement, use INSTEAD OF
argument.
This is in contrast to using the FOR
or AFTER
arguments. When you use those arguments, the trigger fires only when all operations specified in the triggering SQL statement have launched successfully.
In SQL Server, you can use the CREATE TRIGGER
statement to create a trigger.
A trigger is a special type of stored procedure that automatically runs when an event occurs in the database server.
You can create a DML trigger, a DDL trigger, or a logon trigger.
This article provides an example of creating a DML trigger.
Continue reading