SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Table Generator for defined tables


Table Generator for defined tables

Author
Message
foote.ryan
foote.ryan
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 58
Comments posted to this topic are about the item Table Generator for defined tables
Linson.Daniel
Linson.Daniel
Mr or Mrs. 500
Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)

Group: General Forum Members
Points: 563 Visits: 391
I think the system generated would do fine for me.....but informative though ...

and I was wondering why not use the keyword QUOTENAME to get the table name in square brackets '[ ]'
ziangij
ziangij
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4474 Visits: 380
thanks... but there is one issue though...
1. create some user defined types in your database say UdtIntEntity

2. when you execute this query, you will get one row for each type viz. Int, UdtIntEntity for the SAME table column.
ziangij
ziangij
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4474 Visits: 380
ziangij (5/19/2010)
thanks... but there is one issue though...
1. create some user defined types in your database say UdtIntEntity

2. when you execute this query, you will get one row for each type viz. Int, UdtIntEntity for the SAME table column.


try this code...

EXEC dbo.sp_addtype N'UdtIntEntity ', N'int',N'not null'
EXEC dbo.sp_addtype N'udtDesc', N'varchar(500)',N'not null'
EXEC dbo.sp_addtype N'udtName', N'varchar(500)',N'not null'


CREATE TABLE [dbo].[abc](
[col1] INT IDENTITY(1,1) NOT NULL
,[col2] VARCHAR(15) NOT NULL
,[col3] VARCHAR(500) NOT NULL
CONSTRAINT [PK_abc_col1] PRIMARY KEY CLUSTERED
(
[col1] ASC
)
)




then run your code for table abc...

the output will be something like this...


if not exists(select * from sysobjects where id = object_id('abc')
and objectproperty(ID, N'IsUserTable') = 1)
begin
Create Table dbo.abc
(
[col1] int NOT NULL IDENTITY (1, 1)
[col1] UdtIntEntity NOT NULL IDENTITY (1, 1)
,[col2] varchar(15) NOT NULL
,[col2] udtDesc NOT NULL
,[col2] udtName NOT NULL
,[col3] varchar(500) NOT NULL
,[col3] udtDesc NOT NULL
,[col3] udtName NOT NULL
)



Douglas Osborne-456728
Douglas Osborne-456728
SSChasing Mays
SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)SSChasing Mays (620 reputation)

Group: General Forum Members
Points: 620 Visits: 327
Ryan,

In your article I see 'And, the script currently does handle foreign keys. ' Was there supposed to be a does not in there - I don't see the logic for scripting Foreign Keys.

Nice Work,
Doug
foote.ryan
foote.ryan
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 58
Correct. The script does not handle foreign keys. Thanks for catching that.


Thank you,
-Ryan Foote
Iwas Bornready
Iwas Bornready
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38590 Visits: 886
Thanks for the script.
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