Write a SQL statement in the program

xiaoxiao2021-04-04  241

There are many discussions on the storage process on the storage process, and many people recommend writing the SQL statement in the program. This will discuss the writing of the SQL statement in the program.

1

String

strsql

=

"

SELECT [AddressID], [AddressLine1], [AddressLine2], [City], [StateProvinceId], [POSTALCODE], [ROWGUID], [ModifiedDate] from [AdventureWorks]. [Person]. [Address] where city = 'bothell' Order by addressid

"

;

This is the most common way, and it is widely used in development.

1

String

strsql

=

"

SELECT

"

2

"

[AddressID],

"

3

"

[AddressLine1],

"

4

"

[AddressLine2],

"

5

"

[City],

"

6

"

[StateProVinceId],

"

Seduce

"

[Postalcode],

"

8

"

[RowGuid],

"

9

"

[ModifiedDate]

"

10

"

From

"

11

"

[AdventureWorks]. [Person]. [Address]

"

12

"

WHERE

"

13

"

City = 'bothell'

"

14

"

ORDER BY

"

15

"

AddressID

"

;

16

The second way, in addition to making people feel comfortable, there is no benefit.

The way the way shown in the figure is better, can reduce maintenance difficulty, improve development efficiency, and the team should be specified. The first point marked in the figure can look at the SQL statement generated by the following finale in SQL Server 2005, but do not know why SQL SQL statement generated by SQL Server 2005 is still so feet. Microsoft can analyze the SQL statement and make it more conducive to development.

If there are two tables to connect, the inner (Left / Right) Join should also write in one line. In addition, it is recommended to use a simpler English alias instead of Chinese table names.

Oh, is it simple? If you have a better way of writing SQL statements, please let me.

Http://www.cnblogs.com/waxdoll/archive/2006/06/12/424311.html

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

New Post(0)