Altova DatabaseSpy 2023 Enterprise Edition

One of the ways to insert data into a table is creating an INSERT statement and running it against the database. This tutorial step shows you how to generate the INSERT statement automatically.

 

Assuming that the zoo in our tutorial has just hired two new zookeepers, you will create a script that adds these two new employees to the table tblZookeepers.

To generate the INSERT script:

1.Open the "ZooDB" project created previously and double-click the dbs_ic_connected ZooDBConnect data source to connect to it.

2.Click the SQL Editor ic_new-sql-editor toolbar button or select the menu option File | New | SQL Editor (Ctrl+N). A new SQL Editor window opens.

3.In the Online Browser, find the tblZookepers table and, holding the Ctrl key pressed, select all its columns except the ZookID column.

dbs_zoo_generate_insert_01

4.Using the right mouse button, drag and drop the selected columns from the Online Browser into the SQL Editor window. A context-sensitive menu appears.

dbs_zoo_generate_insert_02

5.Select Insert from the context menu. The following statement appears in the SQL window:

 

INSERT INTO [ZooDB].[dbo].[tblZookeepers] ([FirstName],  [LastName], [Address], [City], [State], [Telephone], [DOB])
VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL) ;

 

6.Edit the statement as follows:

 

INSERT INTO [ZooDB].[dbo].[tblZookeepers] ([FirstName], [LastName], [Address], [City], [State], [Telephone], [DOB])
VALUES ('June', 'Bug', '1345 Gorilla Highway', 'Newark', 'NJ', '(515)555-7217', '1963-11-26');

 

7.Create a second INSERT statement and edit it as follows:

 

INSERT INTO [ZooDB].[dbo].[tblZookeepers] ([FirstName], [LastName], [Address], [City], [State], [Telephone], [DOB])

VALUES ('Bruno', 'Katz', '87 Panther Place', 'Trenton', 'NJ', '(515)555-7667', '1969-09-13');

 

8.Click the Execute ic_execute-sql button or press F5.

 

To check the results, open a new SQL Editor window and enter:

 

SELECT * FROM tblZookeepers

 

Click Execute ic_execute-sql to run the statement and notice that two new rows have been inserted into the table.

dbs_zoo_generate_insert_03

© 2017-2023 Altova GmbH