SQL Server – Create a copy of a database table and place it in the same database?

Use SELECT … INTO: SELECT * INTO ABC_1 FROM ABC; This will create a new table ABC_1 that has the same column structure as ABC and contains the same data. Constraints (e.g. keys, default values), however, are -not- copied. You can run this query multiple times with a different table name each time. If you … Read more

How to check SQL Server version

Following are possible ways to see the version: Method 1: Connect to the instance of SQL Server, and then run the following query: Select @@version An example of the output of this query is as follows: Microsoft SQL Server 2008 (SP1) – 10.0.2531.0 (X64) Mar 29 2009 10:11:52 Copyright (c) 1988-2008 Microsoft Corporation Express Edition … Read more

How to report an error from a SQL Server user-defined function

You can use CAST to throw meaningful error: create function dbo.throwError() returns nvarchar(max) as begin return cast(‘Error happened here.’ as int); end Then Sql Server will show some help information: Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value ‘Error happened here.’ to data type int.

A connection was successfully established with the server, but then an error occurred during the pre-login handshake

Solution 1) Clean your VS.Net Solution 2) Rebuild Project. 3) Reset IIS 4) Run the project again. Basically that solved my problem, but in my case i was not getting this error and suddenly my local environment starts giving me above error, so may be that trick work for me.

Which are more performant, CTE or temporary tables?

It depends. First of all What is a Common Table Expression? A (non recursive) CTE is treated very similarly to other constructs that can also be used as inline table expressions in SQL Server. Derived tables, Views, and inline table valued functions. Note that whilst BOL says that a CTE “can be thought of as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)