Recently, when I was working on a project, I encountered a problem, that is, when searching for records, I entered keywords to find the records that meet the conditions. Each field is a keyword at the beginning, and it may be 6 or more fields involved in some searches. It is quite difficult to search. I have been searching for a long time on the Internet. I want to find a full table without specifying fields.
Recently, when I was working on a project, I encountered a problem, that is, when searching for records, I entered keywords to find the records that meet the conditions. Each field is a keyword at the beginning, and it may be 6 or more fields involved in some searches. It is quite difficult to search. I have been searching for a long time on the Internet. I want to find a full table without specifying fields.
Recently, when I was working on a project, I encountered a problem, that is, when searching for records, I entered keywords to find the records that meet the conditions. At the beginning, each field contains a keyword, server space, and 6 or more fields will be involved in some searches, which makes it quite difficult to search. I have been searching for a long time on the Internet and want to find a method that can search the entire table without specifying a field. Unfortunately, I have not found this method. Finally, I found a compromise: define a field in each table. This field stores the sum of all other fields, and you only need to match this field when searching.
The following are the Implementation ideas:
This is because you need to insert a value to this field or update this field when inserting and modifying each piece of data. If you rely on code to control this field, it will be very troublesome: you must always remember where the data is inserted and where the data is modified. Finally, I thought of a trigger and directly created a trigger in the database.
The trigger statement is as follows:
Create trigger [GECOAssets_Trigger]
On [dbo]. [GECOAssets]
Insert, update
As
Update GECOAssets Set
SumText = isnull (SourceID, '') + 'hangzhou' + isnull (SourceName,'') + 'hangzhou' + isnull (StateNow ,'') + 'category' + isnull (BuyDepartment, '') + 'category' + isnull (Factory ,'')
+ 'Authorization' + isnull (SourceType, '') + 'authorization' + isnull (BackInfo ,'')
In this way, I thought it was done. During the final test, I found that all SumText values will be updated or inserted as long as a piece of data is inserted or the value of a field in the table is changed, in US space, when there is a large amount of data or when data is updated and inserted frequently, it will inevitably put a lot of pressure on the database.
At this time, I suddenly remembered the row-level trigger that the teacher talked about when I was a beginner, So Baidu and Google looked for it for a long time. Finally, they came to the conclusion that MS SQLServer does not support row-level triggers. This hit me very badly. After all, I felt that a good method was terminated and my mood was very depressed. However, if you don't give up and don't give up, it's my motto, So Baidu and Google continue to die. Finally, we found that when inserting and updating data, there will be a table called inserted, however, this table will store the data during your update. In this way, I will see a flash: This table will certainly store the ID value of this record, as long as it can get the ID value, you can specify to update a record, so that you can implement the row-level trigger effect. I changed the trigger to the following with a try:
Alter trigger [GECOAssets_Trigger]
On [dbo]. [GECOAssets]
Insert, update
As
Update GECOAssets Set
SumText = isnull (SourceID, '') + 'hangzhou' + isnull (SourceName,'') + 'hangzhou' + isnull (StateNow ,'') + 'category' + isnull (BuyDepartment, '') + 'category' + isnull (Factory ,'')
+ 'Authorization' + isnull (SourceType, '') + 'authorization' + isnull (BackInfo,'') where ID in (select ID from inserted)
Sure enough, it perfectly achieves the row-level trigger effect. Now, you can search for fields not specified in the entire table (of course you still need to specify the SumText field). Although it is not a perfect solution, hong Kong space, but after all, it is still ideal to achieve the desired results. I wonder if you have any better solutions, or are there any third-party components to achieve full-Table keyword search or more popular multi-table joint keyword search?
If you have any, don't be stingy. This is the case for your younger brother...