How to dump a Microsoft SQL Server database to a SQL script?

In SQL Server Management Studio right-click your database and select Tasks / Generate Scripts. Follow the wizard and you’ll get a script that recreates the data structure in the correct order according to foreign keys. On the wizard step titled “Set Scripting Options” choose “Advanced” and modify the “Types of data to script” option to … Read more

How to connect to database from Unity

Please disregard any security risks with this approach Do not do it like this. It doesn’t matter if security will come before or after. You will end of re-writing the whole code because the password is hard-coded in your application which can be decompiled and retrieved easily. Do the connection the correct way now so that you won’t … Read more

An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON SQL Server

Summary SQL Server won’t let you insert an explicit value in an identity column unless you use a column list. Thus, you have the following options: Make a column list (either manually or using tools, see below) OR make the identity column in tbl_A_archive a regular, non-identity column: If your table is an archive table … Read more

Using Excel VBA to run SQL query

Below is code that I currently use to pull data from a MS SQL Server 2008 into VBA. You need to make sure you have the proper ADODB reference [VBA Editor->Tools->References] and make sure you have Microsoft ActiveX Data Objects 2.8 Library checked, which is the second from the bottom row that is checked (I’m using Excel … Read more

How to truncate string using SQL server

If you only want to return a few characters of your long string, you can use: See SQL Fiddle with Demo. This will return the first 15 characters of the string and then concatenates the … to the end of it. If you want to to make sure than strings less than 15 do not … Read more