adding a column description
I'd say you will probably want to do it using the sp_addextendedproperty stored proc.
Microsoft has some good documentation on it.
Try this:
EXEC sp_addextendedproperty
@name = N'MS_Description', @value = 'Hey, here is my description!',
@level0type = N'Schema', @level0name = 'yourschema',
@level1type = N'Table', @level1name = 'YourTable',
@level2type = N'Column', @level2name = 'yourColumn';
GO
How to add column description in CREATE TABLE DDL
According to the documentation this should work:
CREATE TABLE mydataset.newtable (
x STRING(10) OPTIONS(description="denotes value of x"),
y STRING(10) OPTIONS(description="denotes value of y"),
z BIGNUMERIC(35) OPTIONS(description="denotes value of z")
)
Is it possible to add description for column while creating table in MSSQL QUERY
It's clunky in SQL Server. For some reason, they've never adopted the COMMENT
syntax, and you can't add the comments directly in the CREATE TABLE
statement.
After your CREATE
statement, run the system stored procedure sp-addextendedproperty
There's an extended conversation on the topic under this question: SQL Comments on Create Table on SQL Server 2008
add column descriptions in dbt docs
The canonical way to do this is with the codegen package, which generates the files exactly as you have described.
Python Dataframe Adding a description to column
A comment on pandas-dev/pandas#2485 suggests using _metadata
and .attrs
. See https://pandas.pydata.org/pandas-docs/stable/development/extending.html#define-original-properties for more information.
One way to do this is to subclass pandas.DataFrame
and add _metadata
.
Define
_metadata
for normal properties which will be passed to manipulation results.
import pandas as pd
class SubclassedDataFrame(pd.DataFrame):
# normal properties
_metadata = ['description']
@property
def _constructor(self):
return SubclassedDataFrame
data = {"a": [1, 2, 3], "b": [10, 12, 13]}
df = SubclassedDataFrame(data)
df.description = "About my data"
Setting _metadata
in the subclass indicates that these properties should be propagated after manipulation. See the example using .head()
below for a demonstration of the difference between pd.DataFrame
and this subclass.
data = {"a": [1, 2, 3], "b": [10, 12, 13]}
df = SubclassedDataFrame(data)
df.description = "About my data"
df.head().description # prints 'About my data'
df_orig = pd.DataFrame(data)
df_orig.description = "About my data"
df_orig.head().description # raises AttributeError
SQL Server - Can you add field descriptions in CREATE TABLE?
While you can't do it in CREATE TABLE
, you can do it at the same time, in the same database script, using this approach:
CREATE table T1 (id int , name char (20))
EXEC sp_addextendedproperty 'MS_Description', 'Employee ID', 'user', dbo, 'table', 'T1', 'column', id
EXEC sp_addextendedproperty 'MS_Description', 'Employee Name', 'user', dbo, 'table', 'T1', 'column', name
Then you can see your entries using this:
SELECT *
FROM ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', 'T1', 'column', default)
How to add column description with transform_df in Foundry?
Unfortunately it's not currently possible to output column descriptions with transform_df
, you have to use the transform
decorator for this. This is because transform_df
returns a native Spark DataFrame, which doesn't support column descriptions.
More information about column descriptions is available in the Palantir docs on column metadata.
Related Topics
How to Select and Update Rows at the Same Time
How to Add a Not Null Column Without Default Value
Group Data by the Change of Grouping Column Value in Order
How to Add a Variable Number of Hours to a Date in Postgresql
Drop Default Constraint on a Column in Tsql
Selecting Nth Record in an SQL Query
Multiple Aggregate Functions in One SQL Query from the Same Table Using Different Conditions
Performance Difference: Condition Placed at Inner Join VS Where Clause
What Should Be the Best Way to Store a Percent Value in SQL-Server
How to Group by Week in Postgresql
How to Get Column Attributes Query from Table Name Using Postgresql
How to Escape Non-Format Characters in Oracle's To_Char
Django: Using Custom Raw SQL Inserts with Executemany and MySQL