Anyone help me with basic sql script (create database with two tables?)

Soldato
Joined
18 Oct 2002
Posts
8,416
Location
South Central L.A.
Really simple request for you guys, basically I just need a basic script displaying how I would create a database using sql. Is the langauge type between sql and mysql any different?

Lets say

Database is called SalesLedger

Table 1 is called Sales
PK is SalesID
Date
SalesPerson
ClientID (FK)

Table 2 is called Client
PK is ClientID
Address
Town
PostCode

What would the script be, to create this database, implement the fields, define the primary keys and link the two tables together?

Just need a rough model answer to work from as a base!

Thanks
 
Jaffa_Cake said:
If you create it using phpMyAdmin then create it the way you want it using the GUI then just click create it shows you the query it executes, makes things a hell of a lot easier, especially when making installers etc.

Ah, I just need the code though, it's for revision purposes and I'm expected to write down the script to create a database.
 
ok I will have a bash at it,

I just quickly did this, am I far off the mark?

Code:
create table TblSales
(
	SalesID int not null auto_increment,
	Date date,
	SalesPerson varchar(20),
	primary key (SalesID),
	foreign key (TblClient ClientID)
		references TblClient(ClientID)
)

create table TblClient
(
	ClientID int not null auto_increment,
	Address varchar(40),
	Town varchar(20),
	PostCode varchar(10),
	primary key (ClientID)
)
 
Cheers, will that code that I have used work then? Have I correctly identified the primary and foreign keys?
 
Heh, can't seem to get it running on my mac....

Can anyone that knows basic sql check if that script is valid? Will it produce the tables/fields I require with the relevant table links? All I need is a written valid script that I can base my answer off.
 
Code:
create table TblSales
(
	SalesID int not null auto_increment,
	Date date,
	SalesPerson varchar(20),
	primary key (SalesID),
	foreign key (fk_ClientID)
		references TblClient(ClientID)
)

create table TblClient
(
	ClientID int not null auto_increment,
	Address varchar(40),
	Town varchar(20),
	PostCode varchar(10),
	primary key (ClientID)
)

Better?

Can anyone with Sql setup quickly run that to see if it works?
 
Jaffa_Cake said:
You can fix it to help you learn, You are not using MYSQL type query here. Tell me if you get really stuck :P

Do I have to run the code the other way around? So I create TblClient first, because when it tries to create a foreign key to TblClient, it can't because it hasn't been created yet?
 
Back
Top Bottom