?
Solved

INSERT INTO

Posted on 2004-11-24
15
Medium Priority
?
255 Views
Last Modified: 2011-09-20
For the append query INSERT INTO <target>,the <target> is described as "The name of the table or query to append records to.".What I cannot understand is how can the <target> be a query?Besides,how to insert records in the middle,rather than at the end?
0
Comment
Question by:EXwithRaj
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 12672168
post ur sql
0
 

Author Comment

by:EXwithRaj
ID: 12672228
I can't understand why you need some SQL.My query is related to the "target" part of the INSERT INTO statement.It's described in the help as either a table or a query.If it's a query then how can INSERT INTO  be used?
0
 
LVL 6

Expert Comment

by:mmusante
ID: 12672664
> Besides,how to insert records in the middle,rather than at the end?

Just sort the data how you need, You can add a 'order' field and set it to a value
so the data you insert will be in the middle if you get your data ordered by the
'order' field.


Wich DB are you working with?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:mmusante
ID: 12672708
> What I cannot understand is how can the <target> be a query

May be that your insert will be done only on the table
subset defined by the query
0
 
LVL 7

Expert Comment

by:wael_tahon
ID: 12673166
A simple insert statement:

(1) Insert into YourTableName( Column1, Colmn2, Colmn3)   Values(Valu1, Valu2, Valu3)

This insert one row in the "YourTableName"

(2) Insert into YourTableName( Column1, Colmn2, Colmn3)  Select Col1, Col2, Col3 From AnotherTableName where Somthing=2

This insert multible rows in the "YourTableName" from the selection returned from "AnotherTableName "


0
 

Author Comment

by:EXwithRaj
ID: 12673832
wael_tahon,you've not understood the requirements of my query at all.The kind of solution you've provided is not what I require.In fact,you've strangely assumed that I am ignorant of INSERT INTO.Sorry to disappoint you - but I am NOT!
       mmusante  ,on the other hand has understood me.But,mmusante,your solution is vague,therefore,I am unable to gather how it'll work.Furthur input from you is required.
0
 
LVL 6

Expert Comment

by:mmusante
ID: 12674509
Sorry but your question is vague too!

Wich DB are you working with? In both MSSQL-Server and Oracle the <target> for the INSERT INTO steatment is a table or a VIEW (not a query). I'm supposing that you are working with Access (where views are called 'query') but I'm not sure about this.

Views (and queries in Access) if they are UPDATABLE may work like tables and can also be updated.

A view is updatable if it mantain a one-to-one relation vith all origin tables so if you update the view the DBMS can update the data in the tables of origin.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 12674781
The answer is this: some queries are updatable. Depending on the database you are using, the requirements for a query/view to be updatable vary. Generally speaking, the query must contain enough information to identify every record that must be updated (i.e. the primary keys from all tables involved in the query). In addition, the query must contain all not nullable fields from all tables in the query. Under these conditions, you can update the query.
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 80 total points
ID: 12674806
this part of your question:"how to insert records in the middle,rather than at the end?" has no meaning.  The concept of Beginning, Middle  or End has no meaning is a Relational Database.  There is no Beginning, no Middle, and no End.

The physical oder of records is totally without meaning, or relevance.  That is one of the advantages of the relational design, which totally abstracts the physical location of the records, from the display of the records.  You can change the display order to almost anything you want, by using a Query and an appropriate Order BY clause.

AW
0
 

Author Comment

by:EXwithRaj
ID: 12684813
mmusante,you guessed it right - I am using MS Access.I also agree that in MS Access,a View & Query,are the same.
    Arthur Wood,I totally agree with you.The idea of inserting a record in the middle of a database doesn't sound logical at all.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12685927
not only is it not logical, it can't be done.  There is no 'middle' in a relational database.

AW
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12685932
and if you agree, then why did you ask the question (about inserting in the middle) in the first place?

AW
0
 

Author Comment

by:EXwithRaj
ID: 12694715
Arthur Wood,I simply asked the question out of curiosity - and certainly not to waste your time.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

807 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