September 6, 2010 at 4:27 am
Hi All
Sorry but silly question .that is their any command or dmv by which we can check create statements of table
like we can we check sp_help 'table name'. it will give table information.
but we need is sp_(some procedure) which gives create definition of table statement. apart from GUI.
or is their any table like sys.comments where we get its information
September 6, 2010 at 4:30 am
No, unless or until you are tracking it with DDL trigger
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 6, 2010 at 4:36 am
can u give me any example please....i am saying that suppose
create table test1 (name varchar(20), age int)
is create so by any mode apart from gui i can check its ddl creation statement if yesreply then i need any dbcc, sp, dmv
if ddl trigger is only method then need the example of it..please
September 6, 2010 at 4:48 am
If you just want the creation statement, management studio can generated it based on the system tables. From object explorer right click the table, script as -> create
If you want to see the exact statement that was run, you need either a DDL trigger or a trace running at the time the statement was executed.
As for example, why don't you open the documentation and have a look? Quicker than asking here.
http://msdn.microsoft.com/en-us/library/ms189799%28v=SQL.90%29.aspx
http://msdn.microsoft.com/en-us/library/ms186406%28v=SQL.90%29.aspx
http://msdn.microsoft.com/en-us/library/ms175941%28v=SQL.90%29.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 6, 2010 at 4:53 am
refer these links
http://www.sql-server-performance.com/articles/audit/ddl_triggers_p1.aspx
http://www.sqlteam.com/article/using-ddl-triggers-in-sql-server-2005-to-capture-schema-changes
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 7, 2010 at 7:20 am
If you right click on a table and go to properties it displays the create date of the table.
September 7, 2010 at 7:56 am
i went to the trouble of creating a stored proc that does this;
as previous posters already identified, the actual statement is never saved...all you can do is script out the info as a CREATE TABLE statement, which may be formatted differently than the original statement, but is functionally the same:
my proc is sp_getDDL, and it's usage is pretty simple:
-- USAGE: exec sp_GetDDL YourTableName
-- or exec sp_GetDDL 'bob.example'
-- or exec sp_GetDDL '[schemaname].[tablename]'
so if you create a table like this:
create table dbo.tallycalendar ( thedate datetime not null primary key, dayofweek varchar(50) null, isholiday bit null default(0), isworkholiday bit null default(0), isdaylightsavings bit null default (0), holidayname varchar(100) null, )
go
create index ix_tallystuff on tallycalendar (thedate, dayofweek, holidayname)
it produces well formatted results like this:
CREATE TABLE [dbo].[TALLYCALENDAR] (
[THEDATE] DATETIME NOT NULL,
[DAYOFWEEK] VARCHAR(50) NULL,
[ISHOLIDAY] BIT NULL
CONSTRAINT [DF__TallyCale__IsHol__023D5A04] DEFAULT ((0)),
[ISWORKHOLIDAY] BIT NULL
CONSTRAINT [DF__TallyCale__IsWor__03317E3D] DEFAULT ((0)),
[ISDAYLIGHTSAVINGS] BIT NULL
CONSTRAINT [DF__TallyCale__IsDay__0425A276] DEFAULT ((0)),
[HOLIDAYNAME] VARCHAR(100) NULL,
CONSTRAINT [PK__TallyCal__5CB7C64E00551192] PRIMARY KEY CLUSTERED (TheDate))
GO
CREATE INDEX [IX_TallyStuff] ON [TallyCalendar] (TheDate, DayOfWeek, HolidayName)
you can download the code here:
Get DDL for any SQL 2005/2008 table
here's the article i contributed discussion with a lot of improvements:
http://www.sqlservercentral.com/Forums/Topic751783-566-1.aspx
Lowell
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply