When you start creating tables and setting them so they can’t have NULL values, you’ll eventually need a way to define a default value for the column. A default value is one that a column would apply to its record if a value is not provided. To specify the default value in a SQL statement,…
SQL Session – How to Hire a DBA
If you’re not already a member of the Charlotte SQL Server User Group, go now and sign up. This group is a great resource of knowledge and connections to the SQL Server community in Charlotte, NC. Their plan is to get together once a month and discuss a new and interesting topic on SQL Server….
Identity Columns
An IDENTITY column is a column that automatically gets it’s value set by the database engine when a new record is added. This is one of the oldest ways Microsoft SQL has of making sure a record is unique. Even if a user were to insert the same record twice, the IDENTITY will always be…
Computed Columns
What is a Computed Column A computed column is a column that users will not enter data for, but the SQL Server will compute and store a value in. The expression for a computed column may include the names of other columns in the table. These columns can also be combined with literal values and…
Schema
In previous versions of SQL Server we had what we called “owners” of objects. Nearly every time you talked about an object “owner” you were talking about dbo. Think about the default name of any user defined functions you created. They always got “dbo.” added to the beginning of their name by the engine when…
NULL Values, Blank Values, and Table Design
Have you dealt with NULL yet? A field is referred to as NULL if it has not received a value. To specify the NULL-ability of a column using T-SQL, just add NULL after the datatype for the column. To specify that values are required, add NOT NULL. If you don’t specify NULL or NOT NULL,…
Rename a Table or Column
In a previous post, I showed you how to rename a database in Microsoft SQL. If you haven’t already been hit with a request to change the name of a table or column by now… it’s coming. In order to prepare you, I’m not giving you the master sword. It’s almost as helpful, right? To…
Renaming a Database
A topic that you’ll need sooner or later is how to rename a database. You’ll get a request to build a database, and it’ll be documented fairly well. You’ll be coding along, then you get a ping through IM. -> Hey, you know that database you just created for me? <- Yeah. I’ve already built…
SQL 102 — DROP DATABASE
While deleting a database is a fairly rare occurrence, I’m teaching you now, since it’s a pretty easy task to learn. Before teaching you this, you do know rule number 2, right? I bring this up because, you never know when you’ll get a request to drop a database, only to get a call 5…
DROP and Truncate
It’s only a matter of time before you need to clean up after yourself in Microsoft SQL. You’ll have to get rid of an index, or a table, or maybe even a whole database. Indexes, tables, and databases can easily be removed using the DROP statement. The DROP INDEX Statement If you get into trying…