views:

23

answers:

2

Hi, How can i define multiple attribute in database. Suppose the name field. It has three parts: Firstname, Middlename, Lastname. And the Address Attribute:

Street Address City State Zipcode Country .......

+1  A: 

Each part of the name is a separate attribute:

CREATE TABLE People ( 
  persion_id INTEGER NOT NULL PRIMARY KEY, 
  first_name VARCHAR(20),
  middle_name VARCHAR(20),
  last_name VARCHAR(30) )

Similarly for addresses the street_address, city, state_or_province, post_code, and country are generally separate attributes. In some applications you might want to split the street address into building_number, street_name, and additional attributes.

Larry Lustig
Should my student table and Name table be separated or connected by pk-fk constrained? How?
Mr. Flint
Assuming your application is relatively straightforward, your student table IS your name table. Instead of a NAME attribute in your student table you have three attributes FIRST, LAST, MIDDLE plus any other attributes that apply to STUDENT. So, no separate NAME table, just three additional columns in STUDENT.
Larry Lustig
+1  A: 

In a database, each attribute becomes a column e.g.

create table person (firstname varchar(20), middlename varchar(20),
                     lastname varchar(20), ...);
create table address (street_address varchar(30), city varchar(30), ...);
Tony Andrews