Tuesday, May 7, 2013

SQL Maintaining Tables

Print Friendly and PDF

Table Creation

When creating a table, you should normalize the data attributes you want to store in the table. See SQL - Data Base Basics of SQL to find out about normalization.

Decide on a table name, column names, primary key, and data types.

Create a query to track the employees in your company. You need to track employee birthdays, age, and salary. Create a table to store employee name, department, and phone numbers.

Table name: Employees
Column names: EmployeeID, FirstName, LastName, Department, HomePhone, WorkPhone

Next, go through the normalization steps to make sure you don't include data that is better suited for another table.

Create a table:

CREATE TABLE Employees
(
EmployeeID CHAR (50) Primary Key NOT NULL,
FirstName CHAR (50) NOT NULL,
LastName CHAR (50) NOT NULL,
HomePhone CHAR (20),
WorkPhone CHAR (20),
Department CHAR (20)
);

Results: