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


Scripting CREATE INDEX Statements Automatically From Your Tables


Scripting CREATE INDEX Statements Automatically From Your Tables

Author
Message
derek.colley
derek.colley
SSChasing Mays
SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)

Group: General Forum Members
Points: 608 Visits: 603
Comments posted to this topic are about the item Scripting CREATE INDEX Statements Automatically From Your Tables

---

Note to developers:
CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
So why complicate your code AND MAKE MY JOB HARDER??!Crazy

Want to get the best help? Click here http://www.sqlservercentral.com/articles/Best+Practices/61537/ (Jeff Moden)
My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.

rainer 77353
rainer 77353
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 16
Is there a script to move CLUSTERED INDEXES to another filegroup
derek.colley
derek.colley
SSChasing Mays
SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)SSChasing Mays (608 reputation)

Group: General Forum Members
Points: 608 Visits: 603
No - clustered indexes deliberately omitted as often these will be wrapped up with your CREATE TABLE scripts (i.e. when using CREATE TABLE myTable ( this INT PRIMARY KEY ) or ALTER TABLE myTable ADD CONSTRAINT pk_this PRIMARY KEY ( this ) )

---

Note to developers:
CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
So why complicate your code AND MAKE MY JOB HARDER??!Crazy

Want to get the best help? Click here http://www.sqlservercentral.com/articles/Best+Practices/61537/ (Jeff Moden)
My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.

mrsteveerickson
mrsteveerickson
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
I had to modify the example code very slightly to get the code to run:


INSERT INTO test.TableWithIndexes
VALUES (1, 'Defrabuliser', 'Blue', '2009-04-30', 19.99, 0),
(15, 'Unbobulator', 'Green', '2012-01-13', 85.00, 0),
(22, 'Disbibulator', NULL, '2012-11-18', 12.50, 0),
(89, 'Bishbosher', 'Orange', '2008-05-23', 109.99, 1),
(101, 'Jambasher', 'Yellow', '2001-03-03', 3.99, 0)

-- create PK/clustered index with padding/fill factor
GO


/****** Object: Index [ix_pk_productId] Script Date: 12/10/2012 11:51:43 AM ******/
ALTER TABLE [test].[TableWithIndexes] ADD CONSTRAINT [ix_pk_productId] PRIMARY KEY CLUSTERED
(
[productId] ASC
)WITH (PAD_INDEX = ON, FILLFACTOR=90, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Igor Micev
Igor Micev
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: 4469 Visits: 4938
Very handy script.
However, I found a little bug, and here is a recommendation for the little change in the script.

Replace
ip.[column_name]

with
'['+ ip.[column_name]+']'

in two places.
Having column names in square brackets makes omitting failures when reserved words (e.g. create, delete,...) are used for them.


Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9734 Visits: 885
Igor Micev (6/4/2015)
Very handy script.
However, I found a little bug, and here is a recommendation for the little change in the script.

Replace
ip.[column_name]

with
'['+ ip.[column_name]+']'

in two places.
Having column names in square brackets makes omitting failures when reserved words (e.g. create, delete,...) are used for them.
Thanks for the tip.
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9734 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