sys.master_files still have record problems after SQL Server removes transaction logs

After removing the transaction log file in SQL Server, when checking with sys.master_files, it is found that the corresponding transaction log file record information still exists in sys.master_files, except that the state_desc is OFFLINE. It will take some time for this record to disappear from the system view.   DECLARE @db_name NVARCHAR(32) ...

Posted by uatec on Tue, 19 Mar 2019 01:54:27 -0700

Different date formats for getdate()

When using Sql Server to query database, we often need to query date format data. There are certain requirements for date format in sql language. By modifying the last parameter in convert, we can return the time when the format is not clear. The specific implementation is as follows: 1 Select CONVERT(varchar(45), GETDATE(), 0): 08 24 2018 0 ...

Posted by AdamBrill on Tue, 29 Jan 2019 13:54:14 -0800

Several Examples of Sending Mail by msdb.dbo.sp_send_dbmail Function in SQL Database

In the implementation system, from time to time, users put forward the hope that the system can automatically push mail. Because of the limited tools and capabilities at hand, many requirements are realized by using the mail trigger of sql server. Steps: 1. Configure mailbox. Steps are simple, there are many posts on the Internet, manual direct ...

Posted by Pixelsize on Sat, 19 Jan 2019 22:00:13 -0800

Application of SQL server stored procedure sp_send_dbmail (html)

Some time ago, because of work needs, I specially studied the use of sp_send_dbmail. I found that the examples on the Internet were too unfriendly to the novice like me /(o)/~. I had a hard time to finish the project and share it with you, not to talk about theory, just practice! The following are the actual needs: -- ========================== ...

Posted by roflpwnt on Fri, 04 Jan 2019 14:33:09 -0800

SQL Server calculates tempdb size incorrectly using sys.master_files

sys.master_files have been used to calculate the size and usage of tempdb databases, but it is found that sys.master_files can not accurately calculate the size of tempdb databases. As follows:     SELECT       database_id                                AS DataBaseId             ,DB_NAME(database_id)                       AS DataBaseName     ...

Posted by itisme on Tue, 18 Dec 2018 14:48:06 -0800

Laravel Query Builder Complex Query Case: Subquery Implements partition by Partition Query

case Case study: Laravel attaches the top 10 comments to his list of articles? At the same time, the first 10 comments of each article are queried together when getting the list of articles. This is a typical case of partition query, which needs to be partitioned according to the post_id field in the comments table, and sorted according to the ...

Posted by Chrisj on Tue, 18 Dec 2018 08:30:04 -0800

Usage of SQL Server FOR XML PATH and STUFF functions

FOR XML PATH, in fact, it is to show the query result set in XML form, and the results of multiple lines in the same line. Let's write an example below: Suppose we have a workflow:      CREATE TABLE [dbo].[Workflow_Action]( [WorkflowSchema] [nvarchar](128) NULL, [ActionSchema] [nvarchar](128) NULL, [ActionName] [nvarchar](64) NU ...

Posted by Monshery on Mon, 17 Dec 2018 21:36:04 -0800

DB too big? One click helps you shrink all DB file sizes (Shrink Files for All Databases in SQL Server)

This paper introduces a simple SQL script to shrink the size of all non-system DB files in the whole Microsoft SQL Server instance.   As a program ape dealing with SQL every day, it often encounters the situation that DB files are too big and space is full: For developers and testers, if DB data is not particularly important, they will not ...

Posted by bostonmacosx on Wed, 12 Dec 2018 15:06:06 -0800