15-07-20 Database--indexed view programming

Source: Internet
Author: User

1. Index

Add an index, design the interface, right-click on any column--index/key--tap to add an index

2. View

The view is the virtual table we've queried.

Creating views: Create View name

As

SQL query statements--grouping, sorting, in, and so on cannot be written

View Usage: SELECT * from view name

3.SQL programming

Define variable: DECLARE @ variable name data type

Variable assignment: SET @ variable name = value

Output: Print variable or string

Check the car table with the name of the BMW two words

DECLARE @name varchar (20)

Set @name = ' BMW '

SELECT * from car where Name like '% ' [email protected]+ '% '

Check the average of all cars in the car table and output

DECLARE @price decimal (10,4)

Select @price = AVG (price) from Car

print ' average price for all cars: ' +cast (@price as varchar (20))

If ... else usage, if there is no parenthesis, curly braces are replaced with begin end

If judging condition

Begin

The statement to execute

End

Else

Begin

The statement to execute

End

Switch case in C # morphing into database usage

DECLARE @ccname varchar (20)

Set @ccname = ' BMW '

SELECT * from Car where Name is like

Case

When @ccname = ' bmw ' Then '% BMW '

When @ccname = ' Audi ' Then '% Audi '

Else '% '

End

15-07-20 Database--indexed view programming

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.