SQL Server trigger + cursor operation implementation

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 --

21 rules for SQL Server database development

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

Code for obtaining SQL database information

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

How to delete duplicate data in SQLServer

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 @

Experience in using dynamic SQL statements

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,

SQL statement that can obtain the IP address of the client

-- 1: Obtain the IP address of the client./************* IP **************/Declare @ ip varchar (20), @ hst varchar (20), @ SQL varchar (100)Declare @ str varchar (100)Set @ str = 'ping' + Host_Name ()Create table # tmp (aa varchar (200 ))Insert #

The same field value of SQL merge multi-row records

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

Concise memorandum of Data Structure linear table

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

Select into and insert into select table copy statements

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 conversion statement

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

Common SQL Server statements (by function)

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

Update the content of fields in all tables in the database in batches, and handle Trojans first aid

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',

SQL statement used to obtain the numeric part of a string

Copy codeThe Code is as follows:Create function dbo. F_Get_No(@ No varchar (100))RETURNS bigintASBEGINWhile patindex ('% [^ 0-9] %', @ No)> 0BEGINSET @ No = STUFF (@ No, PATINDEX ('% [^ 0-9] %', @ No), 1, '') -- deletes a non-numeric character, the

Common SQL Server partition addition and deletion Algorithms

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@

Some common knowledge about databases

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

SQL Server trigger creation, deletion, modification, and viewing sample code

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

Obtain the id to be inserted next to the auto-increment column.

Copy codeThe Code is as follows:Declare @ Table_name varchar (60)Set @ Table_name = 'pay _ inputpa ';Select so. name Table_name, -- table nameSC. name Iden_Column_name, -- auto-increment field nameIdent_current (so. name) curr_value, -- current

The most common SQL statements

(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

SQL Server Returns the intersection of two strings

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

MSSQL deletes data in all tables of a user in the database.

--> 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.

Total Pages: 923 1 .... 626 627 628 629 630 .... 923 Go to: GO

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.