Kayıtlar

T-SQL etiketine sahip yayınlar gösteriliyor

How to truncate log file in SQL Server 2008

In SQL Server data is stored using two physical files: (.mdf)  extension  which contains the data. (.ldf) extension which contains log. Log file size increases very rapidly and depend on the operation performed on the data. After a long time period this file becomes too large. When log file is too large it takes time to perform some operations like ( attach , de-attach, backup, restore ... etc ). Using the code Step 1. Copy/type the below given SQL. Step 2. Change @DBName to < Database Name>, @DBName_log to Step 3. Execute the SQL. ALTER DATABASE @DBName SET RECOVERY SIMPLE WITH NO_WAIT DBCC SHRINKFILE(@DBName_log, 1) ALTER DATABASE @DBName SET RECOVERY FULL WITH NO_WAIT GO source : http://www.codeproject.com/Tips/625760/How-to-truncate-log-file-in-SQL-Server

T-SQL WITH

USE AdventureWorks2012; GO -- Define the CTE expression name and column list. WITH Sales_CTE (SalesPersonID, SalesOrderID, SalesYear) AS -- Define the CTE query. ( SELECT SalesPersonID, SalesOrderID, YEAR(OrderDate) AS SalesYear FROM Sales.SalesOrderHeader WHERE SalesPersonID IS NOT NULL ) -- Define the outer query referencing the CTE name. SELECT SalesPersonID, COUNT(SalesOrderID) AS TotalSales, SalesYear FROM Sales_CTE GROUP BY SalesYear, SalesPersonID ORDER BY SalesPersonID, SalesYear; GO source : http://msdn.microsoft.com/en-us/library/ms175972.aspx

How to retrieve the top N rows for each group

-- Solution   for   SQL   Server   2000   and   later       SELECT   ProductID ,           CategoryID ,           UnitPrice    FROM     @ Products   p1    WHERE    ProductID   IN  ( SELECT   TOP   3   ProductID                          FROM     @ Products   p2                          WHERE    p1 . CategoryID  =  p2 . CategoryID                          ORDER    BY   UnitPrice ...

Sql mükerrer kayıtları silmek

Resim
Sql Server’da bir tablodaki tekrar eden kayıtları nasıl silebiliriz ? L_User  isminde bir tablo oluşturup tabloya bir kaç kayıt girelim. CREATE   TABLE  [dbo].[L_User] (       [ColumnId] [ int ] IDENTITY (1, 1)  NOT   NULL  ,       [UserName] [ char ] (10)  NULL  ,       [UserPwd] [ char ] (10)  NULL    )  ON  [ PRIMARY ]   Böyle bir örnekte kesin ve doğru bir query şekli olmadığı için kişilere bağlı olarak farklı yöntemler kullanılabilir. while ile döngü kurma, cursor kullanmak, temporary table oluşturmak gibi yöntemler tercih edilebilir. Burada bunlardan bir iki tanesine örnek vereceğim. Bu yöntemlerden en kolayı, identity columndan yararlanmaktır.  Tekrar eden kayıtları gruplayıp en küçük veya en büyük ID’lerini alıp  diğerlerini sileceğiz. DEL...