Setting default DATABASE in Teradata

For the continuous operations which need a particular database, giving database name in each query is not needed.

Example:

SELECT column1 FROM database1.table
SELECT column1 FROM database1.table
SELECT column1 FROM database1.table
SELECT column1 FROM database1.table
INSERT INTO database1.table values(1,'Forget code');
UPDATE database1.table SET column1= 5;


The above statements use the database 'database1' repeatedly.

The below syntax is absolutely legal to use which makes the code more readable.

DATABASE database1;
SELECT column1 FROM table
SELECT column1 FROM table
SELECT column1 FROM table
SELECT column1 FROM table
INSERT INTO table values(1,'Forget code');
UPDATE table SET column1= 5;


Since the database is defined initially, all the statements followed by it will use that database. (Only for the session)
If no database is supplied explicitly, Teradata will choose the default database of its own.