20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1<br />

36<br />

Field Name Data Type Notes<br />

MemberId integer Primary key.<br />

FirstName nvarchar(50) Change data type to vargraphic(50) in IBM DB2 and<br />

to varchar(50) in My<strong>SQL</strong> and MS Access. In Oracle<br />

nvarchar is not available with the default character set;<br />

change to varchar. You must have selected Unicode<br />

character set when creating the database to use nvarchar.<br />

LastName nvarchar(50) Change data type to vargraphic(50) in IBM DB2 and<br />

to varchar(50) in My<strong>SQL</strong> and MS Access. In Oracle<br />

nvarchar is not available with the default character set;<br />

change to varchar. You must have selected Unicode<br />

character set when creating the database to use nvarchar.<br />

DateOfBirth date Change data type to datetime in MS <strong>SQL</strong> Server.<br />

Street varchar(100)<br />

City varchar(75)<br />

State varchar(75)<br />

ZipCode varchar(12)<br />

Email varchar(200)<br />

DateOfJoining date Change data type to datetime in MS <strong>SQL</strong> Server.<br />

Notice that the name and address fields are split into smaller parts. Name is split into FirstName and<br />

LastName; address is split into Street, City, State, and ZipCode. Splitting name and address data makes<br />

searching for specific data more efficient. If you want to search for all members in New York City, then<br />

you simply search the City field. If you store street, city, state, and zip code in one address field, searching<br />

by city is very difficult.<br />

Create the <strong>SQL</strong> table creation code. If you prefer, you can use your RDBMS’s management console to create<br />

the table.<br />

CREATE TABLE MemberDetails<br />

(<br />

MemberId integer,<br />

FirstName nvarchar(50),<br />

LastName nvarchar(50),<br />

DateOfBirth date,<br />

Street varchar(100),<br />

City varchar(75),<br />

State varchar(75),<br />

ZipCode varchar(12),<br />

Email varchar(200),<br />

DateOfJoining date<br />

);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!