Trigger-when table 1 inserts data, Table 1 inserts data into table 2, and trigger inserts data.
-- Trigger Learning
ALTER trigger name on table 1
For insert
As
Begin
If (select count (1) from table 1) = 0
Print 'data not inserted'
Else
Insert into Table 2 (field) select field from inserted
End
-- Stored procedure Learning
(1) Paging
ALTER procedure stored procedure name (
@ PageIndex int,
@ PageSize int
)
As
Declare @ startRow int, @ endRow int
Set @ startRow = (@ pageIndex-1) * @ pageSize + 1
Set @ endRow = @ startRow + @ pageSize-1
Select field name from (
Select *, row_number () over (order by id asc) as number from Table Name
) T
Where t. number between @ startRow and @ endRow;
(2) fetch data from the nth to the nth
ALTER proc [dbo]. [pro_page]
@ StartIndex int,
@ EndIndex int
As
Select count (*) from table name;
Select * from (
Select row_number () over (order by id) as rowId, * from Table Name
) Temp
Where temp. rowId between @ startIndex and @ endIndex
(3) display the last user operation data in the table
Select a. * from test
Inner join (select username, [time] = max (time) from test group by username) B
On a. username = B. username and a. time = B. time