Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Why does Create Table require an int?
Old 07-20-2007, 04:54 PM Why does Create Table require an int?
Skilled Talker

Posts: 99
Trades: 0
Code:
CREATE TABLE person 
(
FirstName varchar(15),
LastName varchar(15),
Age int
)
When I take 'Age int' out of that it fails to create the table. Why does it require that to be there?
Arez20469 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-20-2007, 05:25 PM Re: Why does Create Table require an int?
Experienced Talker

Posts: 44
Trades: 0
It should be like this

CREATE TABLE `person` (
`FirstName` VARCHAR( 15 ) NOT NULL ,
`LastName` VARCHAR( 15 ) NOT NULL
) TYPE = MYISAM ;
JLEville is offline
Reply With Quote
View Public Profile
 
Old 07-20-2007, 05:53 PM Re: Why does Create Table require an int?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Arez, did you simply took of the line, but let the comma on the preceding line ?
This could be the problem.
Otherwise, your query was semantically right, although I'd add an numeric field as a primary key.
Indexes on numeric fields are far more efficient than on varchar fields.

You can use an auto_increment option on the field, to let it increment on every insert, or use a sequence (depending the DB you're using)
Code:
create table person(
  personId int not null auto_increment,
  firstName varchar(255),
  lastName varchar(255),

  primary key (personId)
);
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-20-2007, 06:03 PM Re: Why does Create Table require an int?
Skilled Talker

Posts: 99
Trades: 0
Yeah that's what I did and thanks for help!
Arez20469 is offline
Reply With Quote
View Public Profile
 
Old 07-20-2007, 06:35 PM Re: Why does Create Table require an int?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
For the record, are we talking about MySQL or SQL Server? The syntax in the first post looks like MS, and the first reply is definitely not MS convention.

Anyway, you got the answer, but here's a tip:

It isn't strictly necessary to have a primary key in a table. But there are very, VERY few situations where it really makes sense not to. If a table is going to be used as a log and only ever queried for sums and averages, and you know you're only feeding unique data, you don't need a PK. But if you ever need to update, delete, or select a single row, you need a way to identify that row out of all of what's in your table.

For your person table, you could make firstName + lastName the primary key. I think Tripy recommended an int because they're much faster to compare, and more efficient to index. When you need a foreign key in other tables, an int value makes a great deal more sense than two string values.

But you may want to add a unique constraint to the table to make sure that Forrest Croce isn't allowed two entries. You may not; there actually is another guy who shares my name. It probably depends on the scope of your application. But that's something to consider.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 07-20-2007, 06:47 PM Re: Why does Create Table require an int?
Skilled Talker

Posts: 99
Trades: 0
I couldn't follow most of that, but at least I understood the last part!!!one1
Arez20469 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Why does Create Table require an int?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20501 seconds with 12 queries