How to Insert a Date in a DB2 Databaseby Usha Dadighat
IBM created the DB2 database system as an open environment database solution. This allows users to set up a DB2 database on a range of platforms for either small projects or large enterprise solutions. DB2 databases use the SQL language to form queries or instructions on how to add, remove or select items from the database. SQL uses a special date format as a data type you can insert into a DB2 database.
Click "Start," then click "All Programs." Click the "IMB DB2" folder and click "Command Center" to open the program. Open the SQL code where you need to insert the date. Make sure your program has "connect to [database] user [username] using [password]" and replace [database] with the name of your database and [username] and [password] with any needed username and password to access the database.
Create a table with an entry that accepts the date format. For example "CREATE TABLE sample (name VARCHAR(10), birthday DATE);" will create a table called "sample" with one row and two columns, the first called "name" and the second "birthday."
Insert any entries with the date into the DB2 database using the SQL "INSERT" instruction. For example, "INSERT INTO sample VALUES('Mary', '1980-02-01');" will add an entry to the "sample" database with the name "Mary" and a birthday of February 1, 1980. The SQL date type uses the format "year-month-day" as a standard to reduce confusion. Repeat as needed for any other entries in the table.