Tips for SQL Server addition, deletion, modification, and query

Source: Internet
Author: User

Tips for SQL Server addition, deletion, modification, and query

Insert statement

1. Insert only the default value in the data:

Insert into [DBTrain]. [dbo]. [log_info]
Default values

2. In a field that can be null, if you want to set null, you can press [Ctrl + 0]. Note that zero is not o. If you want to restore the value before modification, press [Esc]

2. Update statement

You can update the first few or a certain percentage of data.

Update top (3) [log_info]
Set info1 = '20140901'

Update top (80) percent [log_info]
Set info2 = '000000'

Three Delete statements can also use top keywords

Select statement

1. With Ties

Run the following SQL: select top 5 * from test
Order by id desc

The results are as follows:

Execute the following SQL statement:

Select top 5 with ties * from test
Order by id desc

It can be seen that the current five records do not show the data with id = 2 completely,

With ties, you can display all the records with id = 2.

To be continued. $ identity, $ RowGuid, Write clause


SQL addition, deletion, modification, and query statements?

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 where field name orderby field name [desc]"
SQL = "select * from data table where field name in ('value 1', 'value 2', 'value 3 ')"
SQL = "select * from data table where field name between value 1and value 2"
(2) update data records:
SQL = "update data table set field name = field value where condition expression"
SQL = "update data table set field 1 = value 1, Field 2 = value 2 ...... Field n = value nwhere condition expression"
(3) Delete data records:
SQL = "where efrom data table where condition expression"
SQL = "deletefrom data table" (delete all records of the data table)
(4) add data records:
SQL = "insertinto data table (Field 1, Field 2, Field 3 ...) Values (value 1, value 2, value 3 ...) "
SQL = "insertinto target data table select * from source data table" (add records of source data table to target data table)

The efficiency of adding, deleting, modifying, and querying SQL Server databases is better.

Cannot be generalized, depending on the specific situation

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.