Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
In this tutorial, learn how to use T-SQL statements to time travel in a warehouse table. Time travel means to query data as it existed at a specific point in time, which is made automatically possible by Fabric Warehouse data retention.
Note
This tutorial forms part of an end-to-end scenario. Aby ukończyć ten samouczek, należy najpierw wykonać następujące samouczki:
- Tworzenie obszaru roboczego
- Tworzenie magazynu
- Ingest data into a Warehouse
Praca z zapytaniami dotyczącymi podróży w czasie
W tym zadaniu dowiesz się, jak utworzyć widok 10 pierwszych klientów według sprzedaży. Użyjesz widoku w następnym zadaniu, aby uruchomić zapytania dotyczące podróży w czasie.
Ensure that the workspace you created in the first tutorial is open.
On the Home ribbon, select New SQL query.
In the query editor, paste the following code. Kod tworzy widok o nazwie
Top10Customers. The view uses a query to retrieve the top 10 customers based on sales.--Create the Top10Customers view. CREATE VIEW [dbo].[Top10Customers] AS SELECT TOP(10) FS.[CustomerKey], DC.[Customer], SUM(FS.[TotalIncludingTax]) AS [TotalSalesAmount] FROM [dbo].[dimension_customer] AS DC INNER JOIN [dbo].[fact_sale] AS FS ON DC.[CustomerKey] = FS.[CustomerKey] GROUP BY FS.[CustomerKey], DC.[Customer] ORDER BY [TotalSalesAmount] DESC;Uruchom zapytanie.
Po zakończeniu wykonywania zmień nazwę zapytania na
Create Top 10 Customer View.In the Explorer pane, from inside the Views folder for the
dboschema, verify that theTop10Customersview exists.
Utwórz nowe zapytanie do obsługi zapytań dotyczących podróży w czasie.
In the query editor, paste the following code. The code updates the
TotalIncludingTaxvalue for a single fact row to deliberately inflate its total sales. Pobiera również bieżący znacznik czasu.--Update the TotalIncludingTax for a single fact row to deliberately inflate its total sales. UPDATE [dbo].[fact_sale] SET [TotalIncludingTax] = 200000000 WHERE [SaleKey] = 22632918; --For customer 'Tailspin Toys (Muir, MI)' GO --Retrieve the current (UTC) timestamp. SELECT CURRENT_TIMESTAMP;Note
Obecnie można używać tylko strefy czasowej uniwersalnej koordynowanej (UTC) na potrzeby podróży czasowej.
Uruchom zapytanie.
Po zakończeniu wykonywania zmień nazwę zapytania na
Time Travel.In the Results pane, notice the timestamp value (your value will be the current UTC date and time).
To retrieve the top 10 customers as of now, in a new query editor, paste the following statement. The code retrieves the top 10 customers by using the
FOR TIMESTAMP AS OFquery hint.--Retrieve the top 10 customers as of now. SELECT * FROM [dbo].[Top10Customers] OPTION (FOR TIMESTAMP AS OF 'YOUR_TIMESTAMP');Zmień nazwę zapytania na
Time Travel Now.Wróć do zapytania
Time Travel, a następnie skopiuj wyniki zapytania za pomocą polecenia Copy.
Return to the
Time Travel Nowquery, and then replaceYOUR_TIMESTAMPwith the timestamp you copied to the clipboard.Uruchom zapytanie i zwróć uwagę, że druga górna wartość
CustomerKeywynosi 49 dlaTailspin Toys (Muir, MI).Zmodyfikuj wartość znacznika czasu na wcześniejszą , odejmując jedną minutę od znacznika czasu.
Ponownie uruchom zapytanie i zwróć uwagę, że druga górna wartość
CustomerKeywynosi 381 dlaWingtip Toys (Sarversville, PA).
Tip
Aby uzyskać więcej przykładów podróży w czasie, zobacz Jak: Przeprowadzać zapytania z użyciem podróży w czasie na poziomie instrukcji.