15-07-20 Database--indexed view programming

Source: Internet
Author: User
Tags switch case

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 write view usage: SELECT * from view name

3.SQL programming

A, defining variables: DECLARE @ variable name data type

B, Variable assignment: SET @ variable name = value

C, output: Print variable or string

For example: 1, check the car table name contains the BMW two characters

DECLARE @name varchar set @name = ' BMW ' SELECT * from car where name like '% ' [email protected]+ '% '

Example: 2. 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 prices for all cars are: ' +cast (@price as varchar (20))

D, If ... else usage (same as C # usage, just if the condition does not require parentheses, curly braces become the begin ... end...else...bigin...end)

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

Note: Do not write a semicolon or comma after the statement ends

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.