On this topic, I also see there are other ways to solve the Internet.
But in terms of performance and code, I have a better idea.
Here to share with you.
The principle is actually very simple,
Knowledge 1, Length function len ();
Knowledge 2, or the
When writing SQL statements, many times you use filter to filter out some records, SQL to filter the criteria for short: SARG (search Argument/sarg)
Copy Code code as follows:
where amount>4000 and amount
Of course, this isn't about SQL
The code is as follows:
Copy Code code as follows:
Use [tempdb]
Go
/****** object:userdefinedfunction [dbo]. [Fun_getpy] Script date:05/23/2012 18:03:45 ******/
SET ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER ON
Go
/*
Get the first
Error message: Error mssqlserversqlserveragent could not be started (Reason:sqlserveragent must be able to connect to SQL Server as SysAdmin, but "(unknown)" is not Sy Members of the Sadmin role).
Operating Environment: WINDOWS2003R2 32bit + mssql2
Most people know that OLE DB is used to read data to a dataset, but how to deal with a dataset after reading is strange. Many people use loops to splice SQL, which is not only error-prone but inefficient, System.Data.SqlClient.SqlBulkCopy is still
Once the hacker gets the Webshell, the hacker knows your SQL Server administrator password, and if SQL Server is not securely set up then the hacker can easily claim and create a new system administrator account, then the hacker will be able to
If you use the Datename () function to get the full English name of the month, but the report needs it, just display the month name abbreviation.
The 12-month abbreviation, only May is the full name and abbreviation, the other month abbreviation
Therefore, the plan first inserts the data into a temporary table, and then analyzes the data for the temporary table.
The question point is how to create a temporary table dynamically. The original insus.net was implemented using the following code:
Method 1:
Copy Code code as follows:
TRUNCATE TABLE TableName
When you delete all the data in a table, it automatically grows zero.
If there is a foreign key reference to this table, this method will be an error (even if the primary
Copy Code code as follows:
--Create test table, insert data
CREATE TABLE Test (code varchar (), [values] varchar (a), [count] int)
INSERT Test SELECT ' 001 ', ' AA ', 1
UNION all SELECT ' 001 ', ' BB ', 2
UNION all SELECT ' 002 ', ' AAA ',
Copy Code code as follows:
--Set up data table CreateTable TestData
(
ID int Identity (1,1) primary key,
Data int,
Cola varchar (20),
Colb varchar (20)
)
Go
--Inserting test data
DECLARE @counts int
DECLARE @i int
Set @counts = 100
Through the interface design is able to manually operate, can not achieve my batch modification thousands of servers.
Because of this a foot would have been executed in bulk.
Environment: Redgate + MSSQL 2008 R2
The following code is used as a minor
Copy Code code as follows:
CREATE function GetColor
(@ well number varchar (50), @ Layer varchar (50))
Returns varchar (200)
As
Begin
declare @sql varchar; set @sql = '
--distinct
Select @sql = @sql + color + ', ' from (
The first is the most traditional way of writing, using variables in the stored procedure as a paging multiplier
Copy Code code as follows:
[C-sharp] View plaincopyprint?create proc P_paged1
@pageSize int, @currentPage int
As
Development often encounter the need for a variety of conditional combination of inquiries, such as three tables, Grade table grade (Gradeid,gradename), Class Class (Classid,classname,gradeid), Student table student (Stuid, STUNAME,CLASSID), now
A very powerful date format function in SQL Server:
Get current system time, GETDATE (): January 08, 2008 Tuesday 14:59
Select CONVERT (varchar), GETDATE (), 0): 2008 10:57am
Select CONVERT (varchar), GETDATE (), 1): 05/16/08
Select CONVERT
When designing a primary key, you often need to consider the following points:
1. Meaningless: The meaningless here is defined from the user's point of view. This nonsense also reduces the information redundancy of the database to some extent. It
Myth #9: Database file shrinkage does not affect performance
Error!
Shrinking a database file does not affect performance only if there is space left at the end of the file, and the TRUNCATEONLY option is specified in the shrink file.
The
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