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