Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to check table creation statement


how to check table creation statement

Author
Message
anshu84onnet
anshu84onnet
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 130
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
Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2924 Visits: 4076
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;-)
anshu84onnet
anshu84onnet
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 130
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
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47177 Visits: 44356
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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2924 Visits: 4076
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;-)
Rick.Cornell.SME
Rick.Cornell.SME
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5305 Visits: 208
If you right click on a table and go to properties it displays the create date of the table.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14933 Visits: 38924
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search