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 08-05-2008, 12:00 PM NEwBie on sql
Novice Talker

Posts: 5
Trades: 0
Hi I am a newbie on the sql statement, i was given a small exercise through the book regarding sql statement, it was told something like :

The PUBLISHERS table will have the attributes ID (3 characters), name (maximum of 30 characters, and city (maximum of 10 characters). The BOOKS table will have the attributes ID (4 characters), title (maximum of 50 characters), author (maximum of 30 characters), publisher ID, and date published. Make reasonable assumptions for the data types of publisher ID and date published.

CREATE TABLE PUBLISHERS(
Publisher_ID int NOT NULL,
Name varchar(50) NOT NULL,
City varchar(50) NOT NULL,
CONSTRAINT PUBLISHERS_PK PRIMARY KEY(Publisher_ID));

CREATE TABLE BOOKS
(
Title varchar(50) NOT NULL,
Author varchar(30) NOT NULL,
DatePublish date NOT NULL,
Publisher_ID int NOT NULL,
CONSTRAINT Title_PK PRIMARY KEY(Title),
CONSTRAINT Publisher_ID FOREIGN KEY(Publisher_ID)
REFERENCES PUBLISHERS(Publisher_ID));

Can any expert(s) advice me on the exercise against my answer, I am so exciting to wait for some one to correct me.
tiger_Big is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-05-2008, 12:24 PM Re: NEwBie on sql
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Looks pretty good to me, except for
Quote:
CONSTRAINT Publisher_ID FOREIGN KEY(Publisher_ID)
The syntax changes depending of the DB you are using, but with postgresql, for example, this would be written:
Code:
...
Publisher_ID  int  NOT NULL references publishers(Publisher_ID),
...
For me, you say that you want an FK on that field, ok, but you don't say in which table the key is placed...
__________________
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 08-06-2008, 09:51 AM Re: NEwBie on sql
Novice Talker

Posts: 5
Trades: 0
Does that mean my sql statement had met the requirement of exercise.
So what do u mean by postgresql.
tiger_Big is offline
Reply With Quote
View Public Profile
 
Old 08-06-2008, 11:07 AM Re: NEwBie on sql
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I mean postgresql is different from oracle which is different from ms sql server which is different from access and so on. Each db has a syntax that belongs to itself, on details like those. But yes, otherwise I think your answer is correct.
__________________
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 08-06-2008, 11:13 AM Re: NEwBie on sql
Novice Talker

Posts: 5
Trades: 0
OO..get u get u..:
) thank alot for ur help
tiger_Big is offline
Reply With Quote
View Public Profile
 
Old 08-11-2008, 01:29 PM Re: NEwBie on sql
Novice Talker

Posts: 5
Trades: 0
In the exercise i was told to : List all the publishers, and the titles and date published of each publisher arranged by publisher name.

I did try to : SELECT NAME,TITLE,DATEPUBLISH FROM BOOKS,PUBLISHERS
GROUP BY NAME;


it turn out abit funny. is my statement correct, if not why.
tiger_Big is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to NEwBie on sql
 

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