Write SQL statements in a program

Source: Internet
Author: User

There are many discussions about stored procedures in the garden. Many people suggest writing SQL statementsProgram.

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 method and is widely used in development.

1 String Strsql = " Select "   +  
2 " [Addressid], "   +  
3 " [Addressline1], "   +
4 " [Addressline2], "   +
5 " [City], "   +
6 " [Stateprovinceid], "   +
7 " [Postalcode], "   +
8 " [Rowguid], "   +
9 " [Modifieddate] "   +
10 " From "   +
11 " [Adventureworks]. [person]. [address] "   +
12 " Where "   +
13 " City = 'bothell' "   +
14 " Order "   +
15 " Addressid " ;
16

The second method has no advantages except making people comfortable.

The statement shown here should be better, which can reduce the maintenance difficulty and improve the development efficiency. These small details should be specified in team development. The first point shown in the figure shows the SQL statements generated through the menu in SQL Server 2005, but I don't know why the SQL statements generated by the SQL Server 2005 query editor are still so lame. Microsoft can parse SQL statements and make them more suitable for development.

If two tables are connected, the inner (left/right) join statements should also be written in one row. In addition, we recommend that you use a simpler english alias instead of a Chinese table name.

It's easy, right? If you have a better solution for writing SQL statements, please let me know.

Related Article

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.