?
Solved

insert into mysql database

Posted on 2004-04-20
3
Medium Priority
?
707 Views
Last Modified: 2008-03-10
Can anyone please tell me how to insert the following into the test database of mysql
i currently have it in a text document

Create table orderForm
(  orderNumber Varchar(22),
ProductName Varchar(22),
Quantity Integer,
Price Varchar(22),
Comment Varchar(220),
status Varchar(22),
primary key (orderNumber)
);

create table staff
(
 username Varchar(22),
 password Varchar(22),
 primary key(username)
);

create table supervisor
(
 username Varchar(22),
 password Varchar(22),
 primary key(username)
);

create table financeDepartment
(
 username Varchar(22),
 password Varchar(22),
 primary key(username)
);


create table product
(
 name Varchar(22),
 price Varchar(22),
 quantity Integer,
 budget double,
 primary key(name)
);

insert into staff values('staff1','staff1');
insert into supervisor values('supervisor1','supervisor1');
insert into financeDepartment values('finance1','finance1');
insert into product values('test1','12.30','12','123,213');
0
Comment
Question by:aka_damo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Expert Comment

by:S1monP
ID: 10873670
1. Log in to MySQL
2. Type "Use test" (assuming test is the name of your database)
3. Assuming your source code is in the bin directory of MySql and your text file is "Tables.sql"
    Type "source Tables.sql;" and press return.

Simple eh?
As a note, if you run the source code above you will get an error telling you that a primary key must be NOT NULL, all you need to do is change the tables as below (and get into the habit of dropping existing tables, it saves a load of hassle)

DROP TABLE IF EXISTS orderform;
DROP TABLE IF EXISTS staff;
DROP TABLE IF EXISTS supervisor;
DROP TABLE IF EXISTS financeDepartment;
DROP TABLE IF EXISTS product;

Create table orderForm
(  orderNumber Varchar(22)NOT NULL,
ProductName Varchar(22),
Quantity Integer,
Price Varchar(22),
Comment Varchar(220),
status Varchar(22),
primary key (orderNumber)
);

create table staff
(
 username Varchar(22) NOT NULL,
 password Varchar(22),
 primary key(username)
);

create table supervisor
(
 username Varchar(22)NOT NULL,
 password Varchar(22),
 primary key(username)
);

create table financeDepartment
(
 username Varchar(22)NOT NULL,
 password Varchar(22),
 primary key(username)
);

create table product
(
 name Varchar(22)NOT NULL,
 price Varchar(22),
 quantity Integer,
 budget double,
 primary key(name)
);

Regards
Simon
0
 

Author Comment

by:aka_damo
ID: 10873768
sorry Simon do i just save the text file as database.sql and place it in C:\mysql\bin ?
I did this and got errors
Sorry im a very novice user
thanx
aka_damo
0
 

Accepted Solution

by:
S1monP earned 240 total points
ID: 10874036
Try copying and pasting the modified text below from my answer above and save as c:\mysql\bin\test1.txt then log into the database and type: source test1.txt
I've assumed you've installed to C: as above and that you are logged in to a database, ie use test..
Just tried this on my machine and it works fine

DROP TABLE IF EXISTS orderform;
DROP TABLE IF EXISTS staff;
DROP TABLE IF EXISTS supervisor;
DROP TABLE IF EXISTS financeDepartment;
DROP TABLE IF EXISTS product;

Create table orderForm
(  orderNumber Varchar(22) NOT NULL,
ProductName Varchar(22),
Quantity Integer,
Price Varchar(22),
Comment Varchar(220),
status Varchar(22),
primary key (orderNumber)
);

create table staff
(
 username Varchar(22) NOT NULL,
 password Varchar(22),
 primary key(username)
);

create table supervisor
(
 username Varchar(22) NOT NULL,
 password Varchar(22),
 primary key(username)
);

create table financeDepartment
(
 username Varchar(22) NOT NULL,
 password Varchar(22),
 primary key(username)
);

create table product
(
 name Varchar(22) NOT NULL,
 price Varchar(22),
 quantity Integer,
 budget double,
 primary key(name)
);


Simon
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question