Insert Into Statement in Teradata

Insert into statement is used to insert a record into a table in Teradata. The syntax of the insert query in Teradata is same like other relational databases such as Oracle, Mysql, SqlServer and so on.

Syntax of Insert statement

  • The database name and table name should be mentioned after the Insert into command.
  • Here the Column1,Column2,..ColumnN are denotes the name of the each column. If you are adding the values for all the columns, column names are optional in the Insert Statement.
  • The Value1,Value2,..ValueN are mentions the value that you want to insert into the table.

Example of Insert Into statement In Teradata

Lets create the Patient table in the Hospital Database and add the few records into it using Insert Into statement.

The above create statement has executed in Teradata and it created the Patient table in Hospital_DB.

Patient table in Teradata
Patient table in Teradata

Now we can run the insert query to add the records into the patient table.

Insert query In Teradata
Insert query In Teradata

Common Errors in Insert Statement of Teradata

Error 1 :

Lets try to add the multiple records using Insert statement in Teradata

Since Teradata won’t support Values with Multiple rows in Insert statement, It will throw the following error message.

To resolve this issue, Teradata provides INSERT INTO SELECT statement to add the multiple values. First we can insert all the records into one temporary table and then we can execute the INSERT INTO SELECT statement to add the multiple records.

Error 2 : The positional assignment has too few values

The number of columns in the Patient table is 6. Lets try to insert the 5 values into this table like below.

In the above Insert query, we didn’t include the value for the BloodGroup column(5th column in the Create table). Since the number of columns is not matched with the number of values in the Insert statement,Teradata has thrown the following error message

To resolve this issue, we need to specify the column names along with values in the Insert statement.

Positional assignment in the Insert query of Teradata
Positional assignment in the Insert query of Teradata

Since we didn’t add the value for BloodGroup column in the Insert statement,the NULL value has added into it.