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
Old 10-23-2008, 08:57 AM Problem With Mysql
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi all,

Pretty new to MYSQL I have created some tables with no problem but having problems with this bit of code if anyone can help please.

create table Booking
(DelNo int not null,
EventNo int not null,
EventB&B bool,
BookingFee Decimal(5,3) not null,
primary key (DelNo))
foreign key (DelNo) references Delegate (DellNo))
primary key (EventNo)
foreign key (EventNo) references Event (EventNo))
engine = innodb;

insert into booking values
(true,20);

create table Event
(EventNo int not null,
EventDate date(yyyy-mm-dd) not null,
primary key (EventNo))
foreign key (HotelNo) references Hotel (HotelNo))
engine = innodb;

insert into booking values
(1,2008-10-19);

I probabley made some silly Mistakes but being new cant seem to see them.
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 10-23-2008, 09:04 PM Re: Problem With Mysql
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
It looks like you're missing commas at the end of a few statements and you aren't closing the opening parenthesis. I think you also have a few parenthesis where you don't need them too.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 10-24-2008, 08:01 AM Re: Problem With Mysql
Brian07002's Avatar
Defies a Status

Posts: 2,140
Name: ...
Location: ...
Trades: 0
Tip: PhpMyAdmin works great especially when you are just starting out, usually in your hosting package.
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 10-24-2008, 03:31 PM Re: Problem With Mysql
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by millwalll View Post
EventB&B bool,
SQL Server would never allow that without [brackets] around the column name, telling the server this is an identifier. In MySQL you use rabbit ears instead of brackets to do that.

Also, you're missing some commas on the ends of a few lines.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 10-24-2008, 05:44 PM Re: Problem With Mysql
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi ive sorted the code out bit as saw few mistake here the new code with the problems I am geting any help be cool thanks

Code:
create table Booking
DelNo int not null,
EventNo int not null,
EventBB bool,
BookingFee Decimal(5,3) not null,
primary key (DelNo)
foreign key (DelNo) references delegate (DelNo)
primary key (EventNo)
foreign key (EventNo) references Event (EventNo))
engine = innodb;
Error I get
Command failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'foreign key (DelNo) references delegate (DelNo) primary key (Ev

the second problem I have is I have used this code

Code:
create table event
(EventNo int not null,
EventDate varchar(10) not null,
HotelNo int not null,
primary key (EventNo),
foreign key (HotelNo) references hotel (HotelNo))
engine = innodb;
When I try use this code to enter data I get this error
Code:
insert into event values
(1,19-10-2008);
Error

Command failed: Column count doesn't match value count at row 1

any help be amazing and again sorry if these are silly question I am very new
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 10-24-2008, 07:02 PM Re: Problem With Mysql
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
With the first table you're missing the opening parenthesis

create table Booking
DelNo int not null,

should be

create table Booking
(DelNo int not null,

followed by the rest.

With the second table the way you're inserting won't work. You're trying to insert 2 values into the table, but MySQL doesn't know which fields. Since you didn't specify it assumes you want to add values to all the columns. You have 3 columns in the table, but you're only inserting 2 values.

You either need to insert the 3rd value for HotelNo or specify which columns you want to insert values into like this:

insert EventNo, Event Date into event values (1,19-10-2008);
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 10-24-2008, 07:21 PM Re: Problem With Mysql
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Code:
create table Booking
(DelNo int not null,
EventNo int not null,
EventB&B bool,
BookingFee Decimal(5,3) not null,
primary key (DelNo)
foreign key (DelNo) references delegate (DelNo)
primary key (EventNo)
foreign key (EventNo) references Event (EventNo))
engine = innodb;
that code I have tried and still get same problem

as for the second bit the reason I am only inserting 2 bits of data is becasue

Code:
create table event
(EventNo int not null,
EventDate varchar(10) not null,
HotelNo int not null,
primary key (EventNo),
foreign key (HotelNo) references hotel (HotelNo))
engine = innodb;
the first bit is the id number what is 1 and the second bit is the data as for the HotelNo I thought that by using that as foreign key it would get the vales u from table and display them so would not need to enter data for it if that makes sense.
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 10-24-2008, 07:25 PM Re: Problem With Mysql
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
problem 2 first:

UNLESS you are filling ALL fields with values, you MUST specify a field list. In your example you have three columns and only two values.
And if you omit the field list the values MUST be the same order as the columns.

and
Code:
 
create table Booking(
DelNo int not null,
EventNo int not null,
EventBB bool,
BookingFee Decimal(5,3) not null,
foreign key (DelNo) references delegate(DelNo),
foreign key (EventNo) references Event (EventNo),
primary key (DelNo, EventNo)
)
engine = innodb;
note the addition of commas
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-24-2008, 07:38 PM Re: Problem With Mysql
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
ok sorted one problem out bit confussed about the other one this is the code
Code:
create table event
(EventNo int not null,
EventDate varchar(10) not null,
HotelNo int not null,
primary key (EventNo),
foreign key (HotelNo) references hotel (HotelNo))
engine = innodb;
Now the first line is the EventNo and next is EventDate so this is the code I am using

Code:
insert into event values
(1,19-10-2008);
The reason I have only 2 bits of information in this is I thought that HotelNo is a foreign key so it would go to my hotel table and get the information out of the HotelNo or is this incorrect?

Many thanks
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 10-24-2008, 08:16 PM Re: Problem With Mysql
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
it's incorrect

how would the query know which hotel number to get if you had 50,000 in the table?

It seems like you misunderstand the purpose of foreign keys, they are there to maintain the referential integrity of the data. So if you deleted HotelNo xx and records still existed in "event" that referenced that particular record it would raise an error.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-26-2008, 07:16 PM Re: Problem With Mysql
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Thanks one more question when I remove the HotelNo from the code like this

Code:
create table event
(EventNo int not null,
EventDate varchar(10) not null,
primary key (EventNo),
foreign key (HotelNo) references hotel (HotelNo))
engine = innodb;
I get this error Command failed: Key column 'HotelNo' doesn't exist in table
I know how to fix this error but dont really want column called HotelNo in this table as it will only confuss things would this work

foreign key references hotel (HotelNo))

many thank
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 10-26-2008, 09:10 PM Re: Problem With Mysql
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
it's a little difficult to have a foreign key on a column that isn't in the table.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-26-2008, 09:11 PM Re: Problem With Mysql
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Nope. A correction.

It's impossible.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-27-2008, 01:38 PM Re: Problem With Mysql
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
ok thanks
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Reply     « Reply to Problem With Mysql
 

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.98600 seconds with 12 queries