Tag: tsql na dziś

Administracja, Development, Przydatne skrypty, SQL Server

RESTORE DATABASE FROM database_snapshot

Z dokumentacji technet: https://msdn.microsoft.com/en-us/library/ms175158%28v=sql.105%29.aspx Snapshots can be used for reporting purposes. Also, in the event of a user error on a source database, you can revert the source database to the state it was in when the snapshot was created. Data loss is confined to updates to the database sinceCzytaj dalej / Read more

Administracja, Development, SQL Server

TRUNCATE tylko części danych? Challenge accepted!

UWAGA Artykuł pochodzi z czasów, gdy nie istniało polecenie TRUNCATE TABLE WITH PARTITIONS . Dlatego został on nieco zmodyfikowany, odpowiednie komentarze prostują sytuację ;] Z dokumentacji technet: https://msdn.microsoft.com/pl-pl/library/ms189461%28v=sql.110%29.aspx Partitioning data enables you to manage and access subsets of your data quickly and efficiently while maintaining the integrity of the entire dataCzytaj dalej / Read more

Development, SQL Server

Zaawansowane przesuwanie okien :D (czyli użycie funkcji „okienkowych” OVER i zastosowanie ROWS,RANGE,BETWEEN,UNBOUNDED, CURRENT, PRECEDING, FOLLOWING)

Z dokumentacji technet: https://msdn.microsoft.com/pl-pl/library/ms189461%28v=sql.110%29.aspx ROWS | RANGE Further limits the rows within the partition by specifying start and end points within the partition. This is done by specifying a range of rows with respect to the current row either by logical association or physical association. Physical association is achieved byCzytaj dalej / Read more

Development, SQL Server

Potęga funkcji okna – SELECT LAG(), LEAD(), FIRST_VALUE(), LAST_VALUE()

Z dokumentacji technet: https://msdn.microsoft.com/en-us/library/hh231256.aspx https://msdn.microsoft.com/en-us/library/hh213125.aspx https://msdn.microsoft.com/en-us/library/hh213018.aspx https://msdn.microsoft.com/en-us/library/hh231517.aspx LAG provides access to a row at a given physical offset that comes before the current row. LEAD provides access to a row at a given physical offset that follows the current row. FIRST_VALUE returns the first value in an ordered set ofCzytaj dalej / Read more

Administracja, SQL Server

Chcesz przyspieszyć backup albo brakuje Ci na niego miejsca choć masz inne dyski które razem go pomieszczą ale z osobna już nie?

Z dokumentacji technet: ( https://technet.microsoft.com/en-us/library/ms190954%28v=sql.105%29.aspx ) Using multiple backup devices allows backups to be written to all devices in parallel. Backup device speed is one potential bottleneck in backup throughput. Using multiple devices can increase throughput in proportion to the number of devices used. Similarly, the backup can be restored fromCzytaj dalej / Read more

Development, SQL Server

Proste usunięcie duplikatów

Dzisiaj prezentacja prostego sposobu na pozbycie się wszystkich rekordów, które nie są takie same ale niestety mają ten sam klucz. Do wykonania takiej operacji posłużymy się oczywiście grupowaniem, ale nie tym klasycznym które wszyscy znamy (GROUP BY), a partycjonowaniem danych przy użyciu funkcji okienkowych (PARTITION BY) Wystarczy ponumerowac rekordy (ROW_NUMBER())Czytaj dalej / Read more

Development, SQL Server

Stosowanie IN do znalezienia jednej wartości w wielu kolumnach

Z dokumentacji technet: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/in-transact-sql IN (Transact-SQL) – Determines whether a specified value matches any value in a subquery or a list. Oficjalna dokumentacja nie wspomina o możliwości wykorzystania polecenia IN do przeszukiwania wielu kolumn dla podanej wartości. Jednak implementacja  przewiduje takie przypadki, pokaże też na co engine zamienia takie polecenie. CzasamiCzytaj dalej / Read more

Development, SQL Server

Sortowanie liczb przechowywanych jako napis

Z wikipedii: http://pl.wikipedia.org/wiki/Porz%C4%85dek_leksykograficzny Porządek leksykograficzny – pojęcie matematyczne odnoszące się do sposobu uporządkowania elementów zbiorów. Dzisiaj krótko o dość często zapominanym szczególe, który może znacząco wpłynąć na wyniki Waszych zapytań. W wielu systemach można napotkać na ciekawe przypadki trzymania liczb w polach (n)char,(n)varchar. Zapewne każdy z nich dałoby się jakośCzytaj dalej / Read more

Development, SQL Server

SQL# (SQLsharp) na przykładzie STRING_SPLIT i REGEX_REPLACE

Z dokumentacji projektu SQLSharp( http://www.sqlsharp.com/download/SQLsharp_Manual.pdf ) Welcome to SQL# (SQLsharp). SQL# is a small .Net / CLR library (Assembly to be specific) that resides in a SQL Server 2005(or newer) database and provides a suite of User-Defined Functions,StoredProcedures, User-Defined Aggregates, and User-Defined Types. This set of toolsis designed to make thelivesCzytaj dalej / Read more