Developing By Me

Project Development and Design

INSERT INTO Syntax

    The INSERT INTO clause is used to add rows to a current table. This option allows the DBA to expand the tables as the need arises with new information. The INSERT INTO clause must conform to the structure of the table and cannot change it. If the database can passively CAST the values it will however there are cases such as a FLOAT to an INT that SQL will give an error. There are two different ways to write the clause. The first uses passive field placement. In this method the fields must be listed in the exact order they are on the table. The second is an explicit placement which allows the DBA to specify which field will have a specific value. In both cases the query could be hard to read but knowing the structure helps with this process.

 

SQL Syntax
INSERT INTO tableVALUES (value1, value2, value3) 
INSERT INTO table (field1, field2, field3)VALUES (value1, value2, value3) 

 

    The VALUES can be provided as literals or predefined but they can also be included as SQL variables or functions. In addition to this method it is also possible to use a subquery which will provide multiple rows in the correct order through the SELECT clause. The subquery option is less common however it has the usefulness to update a backup copy of the table or to add more information to a temporary table that has been created but the results have multiple queries that need to be run.

 

%d bloggers like this: