Copy codeThe Code is as follows:Create trigger tri_wk_CSVHead_History on wk_CSVHead_History-- Declare a tri_wk_CSVHead_History trigger,Instead of insert --- the insert operation is replaced by the following OperationAsBeginDeclare YB cursor --
Here, I am not going to introduce the tips for using SQL Server, nor can I provide a solution to cure all diseases. What I do is to sum up some experience-about how to form a good design. These experiences have come from the lessons I have learned
Copy codeThe Code is as follows:SELECT Name FROM Master... SysDatabases order by Name -- get all databasesSELECT Name FROM [database Name]... SysObjects Where XType = 'U' order by Name -- get all tables in the databaseSelect name from syscolumns
Method 1 Copy codeThe Code is as follows:Declare @ max integer, @ id integerDeclare cur_rows cursor local for select Main field, count (*) from table name group by main field having count (*)> 1Open cur_rowsFetch cur_rows into @ id, @ maxWhile @
In our projects, we often need to use the surface sharding function. The methods I used previously seem so clumsy. At that time, we did this, every time we need to paging the data, we need to paging the table. Don't laugh. It's really stupid. Haha,
1. query the qualified records from the database, store them in a DataTable, traverse the table using c #, and use the primary key in DataRow, then read multiple matching records, merge the Record Content read for the second time, and return it to
Linear table A linear table is an abstraction of a linear structure. A linear structure is characterized by a one-to-one linear relationship between data elements in the structure.The Positional relationships between data elements are arranged one
First sentence: SELECT * INTO [ToTable] FROM [FromTable]The second sentence: insert into [ToTable] ([fild_One], [fild_Two]) SELECT [fild_One], 8 FROM [FromTable]The preceding two statements insert data from [FromTable] to [ToTable], but the two
A simple SQL row-column ConversionAuthor: eagletIn database development, we often encounter the problem of column/column conversion, such as the following problems, three tables for departments, employees, and employees. We need to count a list
1. Simple QueryA simple Transact-SQL query only includes the select list, FROM clause, and WHERE clause. They respectively describe the queried columns and the queriedTables or views, and search conditions. For example, the following statement
Copy codeThe Code is as follows:Declare @ t varchar (255), @ c varchar (255)Declare table_cursor cursor for select a. name, B. nameFrom sysobjects a, syscolumns B, policypes cWhere a. id = B. id and a. xtype = 'U' and c. nameIn ('Char ', 'nchar',
First, add a data table to a partition table:[Dbo]. [SP_Helper_Partition_Add]@ SrcTable nvarchar (256), table to be added@ DestTable nvarchar (256), target table@ IdxOnDest nvarchar (1024): index creation Statement on the target table@
Drop view -- delete a VIEW from a databaseCreate index -- CREATE an INDEX for the database tableDrop index -- delete an INDEX from a databaseCreate procedure -- CREATE a stored PROCEDUREDrop procedure -- delete a stored PROCEDURE from a
1. A trigger is a special stored procedure. It cannot be explicitly called. Instead, it is automatically activated when a record is inserted, updated, or deleted into the table. Therefore, triggers can be used to implement complex integrity
(1) Data Record Filtering:SQL = "select * from data table where field name = field value orderby field name [desc]"SQL = "select * from data table where field name like '% Field Value %' orderby field name [desc]"SQL = "selecttop10 * from data table
The Code is as follows:Copy codeThe Code is as follows:Use tempdbGoIf (object_id ('fn _ getarray') is not null)Drop function dbo. fn_getArrayGoCreate function fn_getArray (@ every 1 varchar (8000), @ every 2 varchar (8000 ))Returns varchar
--> Title: delete data in all tables of a user in the database.--> Author: wufeng4552--> Date: 15:08:41-- Method 1Copy codeThe Code is as follows:Declare @ uname varchar (20)Declare cuser cursorSelect so. nameFrom sysobjects so, sysusers su where so.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.