SQL Server 2008 second day of learning

Source: Internet
Author: User

The last time you learned to add a field to a table in a database, let's continue to learn

--Modify a column field in a database table

Use database

ALTER TABLE name ALTER COLUMN type

--How to delete a column field in a database

Use database

ALTER TABLE table name drop column name

--Delete a table in the database

Use database

DROP table Name

Inserting data into a table in a database use database

Use database

Insert into table name (column 1, column 2) VALUES (' column 1 value ', ' column 2 value ') --Add different types of data to different columns based on column type

--Update a column field in the database

Use database

Update table name set column 1 name = ' column 1 value ', column 2 = ' column 2 value ' ..... --Update the values of individual or multiple columns at once, as appropriate

--The basic syntax of the SELECT statement and the conditional query are given below, because conditional updates are used later, in fact, where the condition is followed

Use database

SELECT * FROM table name -where the "*" indicates that all the field columns in the queried table are queried, and if only the query meets certain criteria, then the WHERE keyword is used

--If you query some fields of a table in the database (if we query the age field and the Name field in the table), then we can write

Use database

Select Age,name from table name --note that we've replaced the previous * number with a specific field that means we're querying some column fields instead of all the fields .

--such as querying all column information in a table, and age satisfies all information that is greater than 20, then we can write

Use database

SELECT * FROM table name where age>20

--Conditional UPDATE statement (for example, the class of the student with age greater than 20 in the Update table is Gao Iban)

Use database

Update table name Set class = ' Sophomore class ' Where Age >20

--Next we will learn a complex UPDATE statement, SQL statements with operations, update the age of AGE=20 students by default + 1 years old, then we can write

Use database

Update table name set age=age+1 where Age=20 -where age=age+1 is age on the original basis +1

--Delete all data from a table in a database

Use database

Delete from table name

--Delete a record in the database, or delete some records that meet the criteria

Use database

Delete from table name where age>21--deletes all records of the table name age greater than 21

SQL Server 2008 second day of learning

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.