Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

Database problem

OpenStudy (anonymous):

@malihe please ask your problem her & my sister @lalaly will help you :)

OpenStudy (anonymous):

*here

OpenStudy (anonymous):

plz see the er diagram in file, i want to insert order of a customer which is first order a product, i related tables must change

OpenStudy (anonymous):

Malihe can you please translate the problem my sister can't understand persian :D

OpenStudy (lalaly):

i'll be back in 5 minutes, my laptop just needs a restart coz i just updated it .. so brb

OpenStudy (anonymous):

okie :)

OpenStudy (anonymous):

oh I get the problem :) she want to insert a record in table order which is related to other tables too so she dont know how to quirie that :)

OpenStudy (anonymous):

OpenStudy (anonymous):

Problem statement: she wants to place a new order but before inserting this order into the table she wants to insert the related information in the other relavent table

OpenStudy (anonymous):

someone please help

OpenStudy (anonymous):

Its my friends question & tomorrow is her exam

OpenStudy (anonymous):

malihe i think it will go like this: INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...); first you will insert a new customer then you will make it sure that the product exist in product table then you place order details & in the end you'll place the order this is what I think dear

OpenStudy (nincompoop):

ewwww windows dba

OpenStudy (nincompoop):

you are missing a lot of information: order status, tracking, and delivery etc etc

OpenStudy (anonymous):

man its not my work its my friend's @malihe work

OpenStudy (anonymous):

@nincompoop can you help her :) kindly use easy english :)

OpenStudy (nincompoop):

I don't know how complex or simple you want your database to be. For generic purposes, first, have a goal in mind how the database should flow from an employee's/store perspective to entering information and then customer's perspective to receiving information there's the customer record basic demographic invoice record discounts returns cancellation payment record balance per order total balance in the account interaction or notes and alerts there are employees accessing or entering order information and there are also employees just receiving payments product records require inventories such as stocks, back-order every goods are either picked up or delivered, consider this also complexity increases depending on the store set-up

OpenStudy (nincompoop):

first things first, what database manager system are you using?

OpenStudy (anonymous):

she is using mysql

OpenStudy (anonymous):

i want to write the sql eqivalent code in java

OpenStudy (nincompoop):

mysql has an automation for a first record entry so long as you set up the order_id

OpenStudy (anonymous):

hmm but nini she wants java code to insert the record

OpenStudy (nincompoop):

java will just pull the records from the server, it just displays them as a text so you needn't worry about that part you want to append or prepend? these are the two types of record insertion

OpenStudy (anonymous):

i use this code to insert :statement.executeUpdate("INSERT INTO Employee VALUES (134, 'zohreh','amini','seller','144')")

OpenStudy (nincompoop):

insert into command

OpenStudy (nincompoop):

stmt.executeUpdate(sql); sql = "INSERT INTO ...

OpenStudy (anonymous):

yes i know that

OpenStudy (nincompoop):

so what is the trouble you're running into?

OpenStudy (anonymous):

i know how to insert in 1 table but as you see my question above and see the er diagram, i don't know how to write this query (insert order of a customer which is first orders a product)

OpenStudy (anonymous):

nini she means she dont know how to write a nasted query that will insert a new order of a customer for a product that already exist :)

OpenStudy (anonymous):

Malihe you will use a "nasted query" search this one on google

OpenStudy (anonymous):

SELECT * FROM ( select (select A from B where ... ) as C from D ) subq WHERE C like ' ... '

OpenStudy (anonymous):

i know this , but i don't see this use for insert anywhere

OpenStudy (anonymous):

you can use it in the same way for insert

OpenStudy (anonymous):

INSERT INTO Orders VALUES (.....) where custID ... smoething like this

OpenStudy (anonymous):

INSERT INTO Staffs VALUES(....) WHERE EXISTS (SELECT * FROM Branch b WHERE s.branchNo = b.branchNo AND city = ‘London’ ); this is proper syntax

OpenStudy (anonymous):

I found it :D

OpenStudy (anonymous):

now can you try it for your tables ?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!