Category Archives: SQL

Useful code snippets in Sql.

Avoid overloading Meaning to Existing Database Column

I’ve always found that when defining a database table it is always best to create a integer primary key, even if a unique key such as social security number, ISBN, or some other business value. Recently I had to go through the unpleasant process of updating a database table and associated scripts, resources, and code [...]

Also posted in Programming, TechKnow | Tagged , , , , , , | 1 Comment

Copy Records From One Database To Another

Most applications require a database of some sorts, and when working with a database you most likely will have a production, development, and test database to work with in addition to backups. A common problem I found is that sometimes I want to move rows of data for a particular database table between the different [...]

Also posted in TechKnow | Tagged , , | Leave a comment

Create SQL Server Database and Database Tables From a File

When working with a database, it’s is always handy to develop a series of scripts to backup, restore, create, move databases around. As of late, I’ve been working with SQL Server a lot so I’ve come to appreciate the sqlcmd utility. You can run the sqlcmd utility from the command line and run a input [...]

Also posted in TechKnow, Tools | Tagged , , , , , , | Leave a comment

Copy Data Between Two Database Tables

There are many situations when you need to copy data from one database table to another one. You may want to migrate data from one database table to a new table, sometimes you need to do so to copy data to a backup table, other times to bulk load data from from different databases. To [...]

Also posted in TechKnow | Tagged , , , , , | 1 Comment

SQL Server Who Lock

When working with SQL Server, two procedures that I use from time to time is sp_who and sp_lock. The sp_who procedure provides information as to which loginame, hostname, dbname are for current users. Usually I am just interested the activity on a given user, which you can use the following SQL command. sp_who @loginame = [...]

Also posted in TechKnow, Tools | Leave a comment

Database Best Practices

Every production application I have been involved with has made use of a database. As a programmer, you don’t have to be a DBA, but just as with software development you need to adhere to a core set of database best practices. Below are a few of the best practices I try to follow. Use [...]

Also posted in Design, TechKnow | 6 Comments