Contents Index Adding new rows with SELECT Changing data using UPDATE

ASA SQL User's Guide
  Adding, Changing, and Deleting Data
    Adding data using INSERT

Inserting documents and images


If you want to store documents or images in LONG BINARY columns in your database, you can write an application that reads the contents of the file into a variable, and supplies that variable as a value for an INSERT statement.

For more information about adding INSERT statements to applications, see How to use prepared statements, and SET statement.

You can also use the xp_read_file system function to insert file contents into a table. This function is useful if you want to insert file contents from Interactive SQL, or some other environment that does not provide a full programming language.

DBA authority is required to use this external function.

Example 

In this example, you create a table, and insert an image into a column of the table. You can carry out these steps from Interactive SQL.

  1. Create a table to hold some images.

    CREATE TABLE pictures
    ( c1 INT DEFAULT AUTOINCREMENT PRIMARY KEY,
       filename VARCHAR(254),
       picture LONG BINARY )
  2. Insert the contents of portrait.gif , in the current working directory of the database server, into the table.

    INSERT INTO pictures (filename, picture)
    VALUES (    'portrait.gif',
       xp_read_file( 'portrait.gif' ) )

For more information, see xp_read_file system procedure.


Contents Index Adding new rows with SELECT Changing data using UPDATE