Wednesday, December 26, 2007

How do you create your database tables?

These days, most database management systems come fully equipped with a graphical user interface (GUI). The GUI allows you to easily do things like create tables, alter them, add new columns, enter data etc.

Creating new tables is a very common database task and I've used a GUI countless times for doing just that.

However, despite the many advantages that a GUI can bring, there are occasions where you shouldn't rely on your GUI. You see, any task you can perform using a GUI can also be done programatically (using a SQL script).

So, when should you use a SQL script to create your tables?
If you use multiple copies of your database (for example, you might have a development environment, a test environment, and a production environment), a script is the perfect way to ensure your table is created exactly the same throughout all copies of your database. Not only this, your script will save you time too. Once created, a script will usually take less than a second to run.

SQL CREATE commands
The actual commands available to you will vary from one database system to the next. Here are some common create commands available to you in SQL Server:
  • CREATE ACTION
  • CREATE CACHE
  • CREATE CELL CALCULATION
  • CREATE CUBE
  • CREATE DATABASE
  • CREATE DEFAULT
  • CREATE FUNCTION
  • CREATE INDEX
  • CREATE MEMBER
  • CREATE MINING MODEL
  • CREATE PROCEDURE
  • CREATE RULE
  • CREATE SCHEMA
  • CREATE SET
  • CREATE STATISTICS
  • CREATE TABLE
  • CREATE TRIGGER
  • CREATE UNIQUE CLUSTERED INDEX
  • CREATE VIEW
So, to create a new database table, you can simply use the CREATE TABLE command. And if you need to create a whole new database, use the CREATE DATABASE command.

No comments: