๐บ๐๐๐-๐๐-๐บ๐๐๐ ๐ฎ๐๐๐ ๐: ๐ฏ๐๐ ๐๐ ๐ช๐๐๐๐๐ ๐ ๐ซ๐๐๐๐ ๐ป๐๐๐๐ ๐๐ ๐ซ๐๐๐๐๐๐๐๐๐?
Delta table can be created in multiple ways depending on your needs. In this post, Iโll walk you through three different methods to create a Delta table in Databricks. Whether youโre working with PySpark, SQL commands, or using the Delta API, each method offers unique advantages for different use cases.
Method 1: Using Delta API (Python)
from delta.tables import *
DeltaTable.createIfNotExists(spark)\
.tableName(โStudentโ)\
.addColumn(โIDโ, โINTโ)\
.addColumn(โNameโ, โSTRINGโ)\
.addColumn(โDepartmentโ, โSTRINGโ)\
.addColumn(โAgeโ, โINTโ)\
.property(โDescriptionโ, โStudent tableโ)\
.location(โ/FileStore/table/delta/createtableโ)\
.execute()
Method 2: Using SQL Syntax
%sql
CREATE TABLE IF NOT EXISTS Employee_02 (
ID INT,
Name STRING,
Department STRING,
Age INT
) USING DELTA
Method 3: Using DataFrame and saveAsTable (PySpark)
data = [(1, โArfinโ, โCSEโ), (2, โPujaโ, โECEโ), (3, โMarryโ, โCEโ)]
columns = [โIDโ, โNameโ, โDepartmentโ]
Get Arfin Parweenโs stories inย yourย inbox
Join Medium for free to get updates fromย thisย writer.
df = spark.createDataFrame(data, columns)
df.show()
df.write.format(โdeltaโ).saveAsTable(โEmployee_03โ)
By following these three methods, you can easily create and manage Delta tables in Databricks for your data engineering workflows. Each method has its own use case โ whether youโre creating a table programmatically, using SQL commands, or working with DataFrames.
Connect with me: https://topmate.io/arfinparween










