shan_chandra
Databricks Employee
Databricks Employee

Hi @BobDobalina  - Dynamic naming of table name is not allowed in DBSQL. However, you can try something similar

%python
from datetime import datetime
date_suffix = datetime.now().strftime("%Y%m%d")
table_name = f"students{date_suffix}"
spark.sql(f"CREATE TABLE IF NOT EXISTS hive_metastore.db.{table_name} AS SELECT * FROM hive_metastore.db.`students`;")

Screenshot 2024-01-11 at 11.19.16 AM.png

Hope this helps!!!

Thanks,

Shan

View solution in original post