0

I want to add data description (information about what each column represents, and some additional information) to my SQL database. It is similar to the label data/label variable command in Stata, and the var.labels attribute of dataframes in R (requires the readstata13 package, can be accessed via varlabel(df)).

Here's an example of what I wanted (taken from the Stata manual):

image

There is a variable label on the variable id to explain what is stored in that column.

I want to know, is this possible in standard SQL (I am using SQLite via the RSQLite package)?

For example, if I want to read/write the labels of a dataframe in R, I can do

library("readstata13")

# df is a dataframe with three columns

# Get labels of all columns
varlabel(df)

# Get label of one specific column
varlabel(df, var.name = "variable_name")

# Set label for all columns
varlabel(df) <- c("label1", "label2", "label3")

# Set label for one specific column
varlabel(df, var.name = "variable_name") <- "This is a label"

I do find this question on Stack Overflow: Add Description From Excel File to Columns description in SQL, which uses the sp_addextendedproperty, but it seems to be an SQL Server-only feature (which, unfortunately, is not a possible option for me).

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • I can't get the code highlighting to use R syntax (putting "R" after the opening ``` doesn't work), so sorry for the awful code highlighting :( – Steve Norkus Jul 12 '23 at 16:42
  • *"add data description ... to my SQL database"* to me sounds like `UPDATE TABLE mytable ADD COLUMN label text` (https://www.sqlitetutorial.net/sqlite-alter-table/). – r2evans Jul 12 '23 at 17:05

0 Answers0