(Transfer) SQL write experience

xiaoxiao2021-03-06  15

Find repetitions in the same table

1.Select * from corp WHERE Enterprise Name in (SELECT Enterprise Name from corp Gropu BY company name Where count> 1)

Multi-condition branching in SQL

2

SELECT FLAG =

Case Enterprise Name When 'China Peking University' Ten '1'

WHEN 'Peking University Philosophy' Then '1'

WHEN 'North University Philosurium' Ten '1'

ELSE Enterprise Name '2' end,

Enterprise name, number of employees, corporate funds, corporate leadership

INTO #TEMP

From corp

SELECT company name, number of employees, corporate funds, corporate leadership

From #Temp

WHERE FLAG in (SELECT FLAGWHERE COUNT (FLAG)> 1)

Judgment using CASE in SQL

SELECT JYID,

Case

Calculate the list of conditions and return one of multiple possible results expressions.

Case has two formats:

The simple case function compares an expression with a set of simple expressions to determine the result. The CASE search function calculates a set of Boolean expressions to determine the result.

Both formats support optional ELSE parameters.

grammar

Simple case function:

Case INPUT_EXPRESSION WHEN WHEN_EXPRESSION THEN RESULT_EXPIPRESSION [... N] [ELSE ELSE_RESULT_EXPRESSION END

CASE search function:

Case when boolean_expression dam_expression [... n] [else else_result_expression end

parameter

Trigger use

When defined for a table or view, INSERT DELETE is defined for a table or view

Update's INSTEAD OF type trigger and executes the corresponding operation, although the trigger is triggered but

The corresponding operation is not performed and is only the trigger SQL statement itself.

The main advantage of the INSTEAD OF trip is that the view that cannot be modified can support modification.

Update operations include two parts, first remove the updated content and insert the new value into

Therefore, a table defining the update type trigger is stored in the delete table when the report will update the operation.

Value new value in the insert table

SQL Server contains several extended stored procedures that can access the system registry. But in fact these extended stored procedures are undisclosed, from SQL Server 7.0, still retain in SQL Server 2000, they may Will delete. But these stored procedures provide the ability to access the system registry in the current SQL Server version, and many people use SQL Server to attack the system, often use these extended stored procedures. So It is best to ban them in SQL Server.

转载请注明原文地址:https://www.9cbs.com/read-46667.html

New Post(0)