Restoring database from .mdf and .ldf files of SQL Server 2008

Yes, it is possible. The steps are: First Put the .mdf and .ldf file in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ folder Then go to sql software , Right-click “Databases” and click the “Attach” option to open the Attach Databases dialog box Click the “Add” button to open and Locate Database Files From C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\folder … Read more

Text was truncated or one or more characters had no match in the target code page When importing from Excel file

I assume you’re trying to import this using an Excel Source in the SSIS dialog? If so, the problem is probably that SSIS samples some number of rows at the beginning of your spreadsheet when it creates the Excel source. If on the [ShortDescription] column it doesn’t notice anything too large, it will default to … Read more

Where are SQL Server connection attempts logged?

You can enable connection logging. For SQL Server 2008, you can enable Login Auditing. In SQL Server Management Studio, open SQL Server Properties > Security > Login Auditing select “Both failed and successful logins”. Make sure to restart the SQL Server service. Once you’ve done that, connection attempts should be logged into SQL’s error log. … Read more

SQL MERGE statement to update data

Assuming you want an actual SQL Server MERGE statement: MERGE INTO dbo.energydata WITH (HOLDLOCK) AS target USING dbo.temp_energydata AS source ON target.webmeterID = source.webmeterID AND target.DateTime = source.DateTime WHEN MATCHED THEN UPDATE SET target.kWh = source.kWh WHEN NOT MATCHED BY TARGET THEN INSERT (webmeterID, DateTime, kWh) VALUES (source.webmeterID, source.DateTime, source.kWh); If you also want to … Read more

How to re-seed a table identity in SQL Server 2008 and undo it all safely?

The command to reset the identity property is DBCC CHECKIDENT (tablename, RESEED, new_reseed_value) When you want to set the column identity to 12345 you run this DBCC CHECKIDENT (beer, RESEED, 12345) When you want to delete test rows and restore the value to the previous value, you do the following. DELETE FROM beer WHERE beer_id … Read more

Cannot resolve the collation conflict between “SQL_Latin1_General_CP1_CI_AS” and “Latin1_General_CI_AI” in the equal to operation

Just use the following syntax to collate on the fly when joining tables with different collations. I integrate systems, so I have to do this a lot. select * from [Product] p join [category] c on c.[Name] collate SQL_Latin1_General_CP1_CI_AS = p.[Name] collate SQL_Latin1_General_CP1_CI_AS