Click here to Skip to main content
16,012,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to know when a column was created for a particular table..

For example
Table1 is having 2 columns like EMPID,EMPNAME

After few days now i am adding 2 more columns to the 'Table1' as 'Location' and 'ActiveYn'

Now i want to know when all these particular columns are added to the table
Posted

In my opinion it's not possible to get creation date for particular column, but it's possible to get modified date for table.

[EDIT]
Thanks RedDK for comment and useful information ;)
[/EDIT]


Just test it (change to your needs):
SQL
USE LIDL;
GO

DECLARE @tableName VARCHAR(50)
DECLARE @columnName VARCHAR(50)

SET @columnName = 'AAA'
SET @tableName = 'Import'

--show create date and modify date before altering table
SELECT obj.create_date, modify_date
from sys.objects obj
inner join sys.columns col on obj.object_Id=col.object_Id
WHERE col.name = @columnName and obj.Name=@tableName

--insert new column
ALTER TABLE Import ADD COLUMN AAA INT NULL
GO

--view create_date and modify_date after altering table
SELECT obj.create_date, modify_date
from sys.objects obj
inner join sys.columns col on obj.object_Id=col.object_Id
WHERE col.name = @columnName and obj.Name=@tableName


See: sys.objects (Transact-SQL)[^]
 
Share this answer
 
v2
Comments
RedDk 23-Jul-13 14:00pm    
(ALTER TABLE Import ADD AAA INT NULL) ...

But one could "know" the ALTER TABLE date by doing two things:
1. SELECT * FROM [LIDL].sys.objects WHERE [object_id] >100 ORDER BY [create_date] DESC -- shows "Import"
2. SELECT * FROM [LIDL].sys.columns WHERE [object_id] = 2117582582 -- hypothetical id, right?


Then do the ALTER and compare. You WILL see a modify_date that gets a tick. THAT might be enough for step one.
Maciej Los 23-Jul-13 14:51pm    
That's interesting... I need to check it.
[EDIT]modify_date - this is it! But the main thought is correct: it's not possible to get the date of creation of particular column.
Thanks RedDK.[/EDIT]
Hi,

Have a look here:
http://stackoverflow.com/a/1425577[^]
 
Share this answer
 
Comments
Member 9848727 23-Jul-13 5:53am    
It is returning the error as invalid column name for both the column name and the table name
Thomas Daniels 23-Jul-13 6:00am    
Unfortunately, I don't find any other solutions. I'm sorry.
Maciej Los 23-Jul-13 6:07am    
Your solution is OK.* I think OP does not set both variables: columnName and tableName or does not have permission to fetch information from master db.
[EDIT]
* - in my opinion this is not possible to get creation date for particular column ;( See my answer
[/EDIT]
Thomas Daniels 23-Jul-13 6:20am    
Maciej Los wrote:
See my answer

I don't see your answer. Is is not yet posted, or have you removed it?
[EDIT]
Now I see your answer!
[/EDIT]
Maciej Los 23-Jul-13 6:24am    
It's posted now ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900