ManojkMohan
Honored Contributor II

Root Cause:
The table or view s_test already exists in the catalog.

The code tries a CREATE TABLE without IF NOT EXISTS or without dropping the existing table first.

The underlying Spark or SQL engine enforces uniqueness of table names and raises an error if the same name is reused improperly.

Usually if there is a Repeated CREATE TABLE commands in code or pipeline without handling existence.   Solution: 

Approach

DescriptionCode Example
Use IF NOT EXISTSAvoid error by conditionally creating table only if it does not exist.CREATE TABLE IF NOT EXISTS s_test (...)
Add OR REPLACE for ViewsFor materialized views, replace existing with new definition.CREATE OR REPLACE VIEW s_test AS ...
Drop Table Before CreateExplicitly drop existing table before creation, ensures clean slate.DROP TABLE IF EXISTS s_test; CREATE TABLE s_test (...)
Use Spark Write ModesUse Spark DataFrameWriter mode("append") or mode("overwrite") depending on use case.df.write.mode("append").saveAsTable("s_test")
Use OR REFRESH for StreamingIf streaming table, use OR REFRESH clause if supported to refresh streaming query.CREATE STREAMING TABLE OR REFRESH s_test (...)