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…
Tag: SQL102
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…
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…
SQL 102 — CREATE DATABASE
The most fundamental task you’ll have to learn to do as a Database Administrator is to create a database. Please remember it’s probably a good idea to make sure you’re connected to the master database on your server when creating databases. Don’t change your connection to your database until you’ve closed out your CREATE DATABASE…
ALTER TABLE
After you’ve spent time designing the perfect table, someone is going to come along and ask you a question that will lead you to changing your table. It can be something as simple as, hey, we can only store 25 characters for a city name, we need to have 50. Or it can be a…
SQL 102 – Foreign Keys
In the simplest terms a Foreign Key in one table refers to the Primary Key of another table. Let’s go back to our demo tables products and productSales. –Products: productName price quantity color ———– —– ——– —– pencil 0.25 100 yellow pen 0.99 73 blue paper 1.00 500 white Mountain Dew 1.25 8 green –prodctSales:…
SQL 201 – Statistics
Microsoft SQL Servers collect statistical information on indexes and column data stored in each database. These statistics are used by the query optimizer to choose the most efficient way to execute your queries. Good statistics hep the optimizer to asses the cost of different query plans, then choose the “best” method to execute your query….