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 (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 58
Comments posted to this topic are about the item Table Generator for defined tables
Linson.Daniel
Linson.Daniel
SSC-Addicted
SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)SSC-Addicted (481 reputation)

Group: General Forum Members
Points: 481 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
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3955 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
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3955 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
SSC-Addicted
SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)

Group: General Forum Members
Points: 462 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 (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

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


Thank you,
-Ryan Foote
Iwas Bornready
Iwas Bornready
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29554 Visits: 885
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