Friday, March 30, 2012
Scripting an index to a table
Example: tableA with fieldB- create an index on fieldBCheck out CREATE INDEX (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_create_64l4.asp).
-PatP|||Originally posted by Pat Phelan
Check out CREATE INDEX (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_create_64l4.asp).
-PatP
Thank you! I found it immediatley after I submitted the post|||Does anyone know the correct procedure to setup a pull relationship from MS Access to a SQL database and vice versa?|||Refer to your post http://www.dbforums.com/t994687.html
Wednesday, March 28, 2012
Scripted CREATE INDEX
sorts of scripts, including the creation of indexes.
I works, however the script contains the CREATE TABLE statements as
well. I want the scripts to recreate the scripts on another filegroup
(testing a theory from previous post).
Am I missing a switch in the wizard to exclude CREATE TABLE?
I did create the script, but then I manually deleted all the CREATE
TABLE statements, which was a pain.
Thanks
RobOn Mar 12, 11:55 am, "rcamarda" <robert.a.cama...@.gmail.comwrote:
Quote:
Originally Posted by
I haveSQLServer 2005 x64. I found in the studio I cangenerateall
sorts of scripts, including the creation of indexes.
I works, however thescriptcontains the CREATE TABLE statements as
well. I want the scripts to recreate the scripts on another filegroup
(testing a theory from previous post).
Am I missing a switch in the wizard to exclude CREATE TABLE?
I did create thescript, but then I manually deleted all the CREATE
TABLE statements, which was a pain.
Thanks
Rob
If you want to fine-tune what gets scripted, you might want to check
out this free app I wrote using SMO:
http://www.elsasoft.org/tools.htm
it will generate scripts for all objects in any 2000 or 2005 db. You
could easily modify it to script only indexes. source code is
available. implemented in C#.
Friday, March 23, 2012
Script to change cluster index to non cluster
We have many tables which have cluster index on column with datatype 'Char(200)'.
Does anyone have script to change cluster index to noncluster for all user tables which have clustered index on a column with 'char(200)' datatype.
Thanks,
DeepakDon't know the direct way, but refer to this Devx article (http://www.dev-archive.com/codemag/Article/11516) to script the indexes and modify so on.
HTH|||Here's a link to the SQL Server system tables download:
http://www.microsoft.com/sql/techinfo/productdoc/2000/systables.asp
So, you would do something like this to get all the clustered indexes that includes a CHAR200 col:
SELECT i.name
FROM sysindexes i,
sysobjects o,
syscolumns c
WHERE o.id = i.id
AND o.type = 'U' -- user table
AND indid = 1 -- clustered index
AND o.id = c.id
AND c.type = ??
AND c.length = 200 ?
For c.type look through systypes and find the CHAR, I don't know offhand what the type ID for a char is. And I am not sure if c.length is 200 or what -- take a look in syscolumns and find a couple of the columns you are targeting and see if they have the same data.
Wednesday, March 21, 2012
Script Table, Index, Stored Procedures from Table list
to generate these objects. The script will be applied to another datbase to
generate these objects.
The 2000 objects name have been loaded into a Table A.
Please help put together a program that will read the object names from
Table A and generate a sql script for objects.
Thank You,Option#1
Try from Enterprise Manager (Tools -> Generate SQL Scripts)
Option#2
Try Import\Export utility from Enterprise Manager
Thanks,
RK
"Joe K." wrote:
> I have a list of approximately 2000 objects that need to create a sql scri
pt
> to generate these objects. The script will be applied to another datbase
to
> generate these objects.
> The 2000 objects name have been loaded into a Table A.
> Please help put together a program that will read the object names from
> Table A and generate a sql script for objects.
> Thank You,
>|||I would like to way read from a table to "Generate SQL Scripts".
I would like to automate the "Generate SQL Scripts" procedure.
Thanks,
"Ram Kumar Koditala" wrote:
> Option#1
> Try from Enterprise Manager (Tools -> Generate SQL Scripts)
> Option#2
> Try Import\Export utility from Enterprise Manager
> Thanks,
> RK
> "Joe K." wrote:
>|||You'll have to use SQL DMO to do this. See if the following links help:
http://www.karaszi.com/SQLServer/in...rate_script.asp
http://www.databasejournal.com/feat...cle.php/1480901
Anith
Script Table with secondary indexes
I used the option "Script Table" --> "Create to" in SQL Server Management Studio Express for a table with secondary index (like IX_IndexName), but in the .sql script file there is only the instruction for the primary key and not for the secondary (I expected something like CREATE INDEX). What can I do?
Hi,its not within the context menu, you have to do it via the script wizard which can be found by right clicking on the database and choosing to script the database objects. In the next steps you can switch a boolean to create also the indexes within the table.
HTH, jens Suessmeyer.
http://www.sqlserver2005.de
|||
It work fine, very thanks
Monday, March 12, 2012
script index
i have four indexes on a table.
i was wondering if anybody can tell me how to script an existing index?
i know how to do this in 2000...wondering how to do in 2005
thanks
? Hi RookieDBA, In Query Analyzer: 1. Hit F8 to open the object explorer; 2. Locate correct database; go to User Tables, find right table and drill down to "Indexes" 3. Right-click Index; choose Script Object to New Window As / Create -- Hugo Kornelis, SQL Server MVP <RookieDBA@.discussions..microsoft.com> schreef in bericht news:ec51452a-622b-48dc-aa2b-dc2ebb7db970@.discussions.microsoft.com... i have four indexes on a table. i was wondering if anybody can tell me how to script an existing index? i.e the sql used to create the index thanks
Script generation for Objects - Management Studio
How do I generate a single script for each object - table, view, index, trigger, sp, function etc.... in SQL Server. The script that is generated from SQL Server wizards is in a single file.
I want to have separate file for each of the objects.
In EM, you right-click on the object, select 'all tasks', then 'Generate SQL Script'. I do not have access to Management Studio right now, so this may or may not be much help.
Do you have access to Enterprise Manager? You can run SQL Server 2000 and 2005 side by side, so it may be worthwhile installing if you cannot do this in MS.
Clarity Consulting (http://www.claritycon.com)
|||Well we have the same feature in SQL 2005 but I need one individual file for each object. I do not want the script of say all tables in file. I want this in different files with file name as table name that is getting scripted.
It applies to other objects like procs, funcs, triggers, constraints, FKs etc
|||You might look at Scriptio. I use it to create .sql files off of my db schema. On the 2nd tab I select ONE FILE PER OBJECT. www.sqlteam.com. The only problem I have found is that existing sql files (we re-exporting) can't be read-only.|||Currently, the Generate Script Wizard can only create a single file. We plan to implement file-per-object functionality in SP2.Script generation for Objects - Management Studio
How do I generate a single script for each object - table, view, index, trigger, sp, function etc.... in SQL Server. The script that is generated from SQL Server wizards is in a single file.
I want to have separate file for each of the objects.
In EM, you right-click on the object, select 'all tasks', then 'Generate SQL Script'. I do not have access to Management Studio right now, so this may or may not be much help.
Do you have access to Enterprise Manager? You can run SQL Server 2000 and 2005 side by side, so it may be worthwhile installing if you cannot do this in MS.
Clarity Consulting (http://www.claritycon.com)
|||Well we have the same feature in SQL 2005 but I need one individual file for each object. I do not want the script of say all tables in file. I want this in different files with file name as table name that is getting scripted.
It applies to other objects like procs, funcs, triggers, constraints, FKs etc
|||You might look at Scriptio. I use it to create .sql files off of my db schema. On the 2nd tab I select ONE FILE PER OBJECT. www.sqlteam.com. The only problem I have found is that existing sql files (we re-exporting) can't be read-only.|||Currently, the Generate Script Wizard can only create a single file. We plan to implement file-per-object functionality in SP2.Script for reindexing
Is there any script available to reindex/ re-create index in a given
database.
Important is that script should first create clustered indexes and then non
clustered indexes as recommended by Microsoft.
Regards,
KayYou can generate a SQL script (ensuring to select both DROP and ADD
syntax when setting up the scripting) and then run this to
drop/re-create indexes.
ALI
Kay wrote:
> Dear all,
> Is there any script available to reindex/ re-create index in a given
> database.
> Important is that script should first create clustered indexes and then no
n
> clustered indexes as recommended by Microsoft.
> Regards,
> Kay|||Run the following script in Query Analyzer and set the result as Text to
generate a script that reindexes all the indexes in the right order:
SELECT 'SELECT ''Reindexing index ' + name + ' on table ' + OBJECT_NAME (id)
+ ''''+ CHAR(13) +
'DBCC DBREINDEX(0, ''' + OBJECT_NAME (id) + ''', ''' + name + ''')'
-- + CHAR(13) +
-- 'DBCC SHRINKFILE(1, TRUNCATEONLY)'
FROM sysindexes
WHERE indid BETWEEN 1 AND 254
AND OBJECTPROPERTY(id, 'IsMSShipped') = 0
AND INDEXPROPERTY(id, name, 'IsStatistics') = 0
ORDER BY OBJECT_NAME(id), indid
Jacco Schalkwijk
SQL Server MVP
"Kay" <CallDBA@.hotmail.com> wrote in message
news:%23qXB4f62FHA.3000@.TK2MSFTNGP12.phx.gbl...
> Dear all,
> Is there any script available to reindex/ re-create index in a given
> database.
> Important is that script should first create clustered indexes and then
> non clustered indexes as recommended by Microsoft.
> Regards,
> Kay
>
>|||Books Online, DBCC SHOWCONTIG. Here you find a script that only defrag if fr
ag level is above a
certain threshold. It is easy to change the script to execute DBCC BREINDEX
instead of INDEXDEFRAG.
See http://www.microsoft.com/technet/pr...ver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote
in message
news:e%23W1yy62FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Run the following script in Query Analyzer and set the result as Text to g
enerate a script that
> reindexes all the indexes in the right order:
> SELECT 'SELECT ''Reindexing index ' + name + ' on table ' + OBJECT_NAME (i
d)
> + ''''+ CHAR(13) +
> 'DBCC DBREINDEX(0, ''' + OBJECT_NAME (id) + ''', ''' + name + ''')'
> -- + CHAR(13) +
> -- 'DBCC SHRINKFILE(1, TRUNCATEONLY)'
> FROM sysindexes
> WHERE indid BETWEEN 1 AND 254
> AND OBJECTPROPERTY(id, 'IsMSShipped') = 0
> AND INDEXPROPERTY(id, name, 'IsStatistics') = 0
> ORDER BY OBJECT_NAME(id), indid
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Kay" <CallDBA@.hotmail.com> wrote in message news:%23qXB4f62FHA.3000@.TK2MS
FTNGP12.phx.gbl...
>
Script for reindexing
Is there any script available to reindex/ re-create index in a given
database.
Important is that script should first create clustered indexes and then non
clustered indexes as recommended by Microsoft.
Regards,
KayYou can generate a SQL script (ensuring to select both DROP and ADD
syntax when setting up the scripting) and then run this to
drop/re-create indexes.
ALI
Kay wrote:
> Dear all,
> Is there any script available to reindex/ re-create index in a given
> database.
> Important is that script should first create clustered indexes and then non
> clustered indexes as recommended by Microsoft.
> Regards,
> Kay|||Run the following script in Query Analyzer and set the result as Text to
generate a script that reindexes all the indexes in the right order:
SELECT 'SELECT ''Reindexing index ' + name + ' on table ' + OBJECT_NAME (id)
+ ''''+ CHAR(13) +
'DBCC DBREINDEX(0, ''' + OBJECT_NAME (id) + ''', ''' + name + ''')'
-- + CHAR(13) +
-- 'DBCC SHRINKFILE(1, TRUNCATEONLY)'
FROM sysindexes
WHERE indid BETWEEN 1 AND 254
AND OBJECTPROPERTY(id, 'IsMSShipped') = 0
AND INDEXPROPERTY(id, name, 'IsStatistics') = 0
ORDER BY OBJECT_NAME(id), indid
Jacco Schalkwijk
SQL Server MVP
"Kay" <CallDBA@.hotmail.com> wrote in message
news:%23qXB4f62FHA.3000@.TK2MSFTNGP12.phx.gbl...
> Dear all,
> Is there any script available to reindex/ re-create index in a given
> database.
> Important is that script should first create clustered indexes and then
> non clustered indexes as recommended by Microsoft.
> Regards,
> Kay
>
>|||Books Online, DBCC SHOWCONTIG. Here you find a script that only defrag if frag level is above a
certain threshold. It is easy to change the script to execute DBCC BREINDEX instead of INDEXDEFRAG.
See http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx for more
information.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote in message
news:e%23W1yy62FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Run the following script in Query Analyzer and set the result as Text to generate a script that
> reindexes all the indexes in the right order:
> SELECT 'SELECT ''Reindexing index ' + name + ' on table ' + OBJECT_NAME (id)
> + ''''+ CHAR(13) +
> 'DBCC DBREINDEX(0, ''' + OBJECT_NAME (id) + ''', ''' + name + ''')'
> -- + CHAR(13) +
> -- 'DBCC SHRINKFILE(1, TRUNCATEONLY)'
> FROM sysindexes
> WHERE indid BETWEEN 1 AND 254
> AND OBJECTPROPERTY(id, 'IsMSShipped') = 0
> AND INDEXPROPERTY(id, name, 'IsStatistics') = 0
> ORDER BY OBJECT_NAME(id), indid
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Kay" <CallDBA@.hotmail.com> wrote in message news:%23qXB4f62FHA.3000@.TK2MSFTNGP12.phx.gbl...
>> Dear all,
>> Is there any script available to reindex/ re-create index in a given database.
>> Important is that script should first create clustered indexes and then non clustered indexes as
>> recommended by Microsoft.
>> Regards,
>> Kay
>>
>
Script for reindexing
Is there any script available to reindex/ re-create index in a given
database.
Important is that script should first create clustered indexes and then non
clustered indexes as recommended by Microsoft.
Regards,
Kay
You can generate a SQL script (ensuring to select both DROP and ADD
syntax when setting up the scripting) and then run this to
drop/re-create indexes.
ALI
Kay wrote:
> Dear all,
> Is there any script available to reindex/ re-create index in a given
> database.
> Important is that script should first create clustered indexes and then non
> clustered indexes as recommended by Microsoft.
> Regards,
> Kay
|||Run the following script in Query Analyzer and set the result as Text to
generate a script that reindexes all the indexes in the right order:
SELECT 'SELECT ''Reindexing index ' + name + ' on table ' + OBJECT_NAME (id)
+ ''''+ CHAR(13) +
'DBCC DBREINDEX(0, ''' + OBJECT_NAME (id) + ''', ''' + name + ''')'
-- + CHAR(13) +
-- 'DBCC SHRINKFILE(1, TRUNCATEONLY)'
FROM sysindexes
WHERE indid BETWEEN 1 AND 254
AND OBJECTPROPERTY(id, 'IsMSShipped') = 0
AND INDEXPROPERTY(id, name, 'IsStatistics') = 0
ORDER BY OBJECT_NAME(id), indid
Jacco Schalkwijk
SQL Server MVP
"Kay" <CallDBA@.hotmail.com> wrote in message
news:%23qXB4f62FHA.3000@.TK2MSFTNGP12.phx.gbl...
> Dear all,
> Is there any script available to reindex/ re-create index in a given
> database.
> Important is that script should first create clustered indexes and then
> non clustered indexes as recommended by Microsoft.
> Regards,
> Kay
>
>
|||Books Online, DBCC SHOWCONTIG. Here you find a script that only defrag if frag level is above a
certain threshold. It is easy to change the script to execute DBCC BREINDEX instead of INDEXDEFRAG.
See http://www.microsoft.com/technet/pro.../ss2kidbp.mspx for more
information.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid > wrote in message
news:e%23W1yy62FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Run the following script in Query Analyzer and set the result as Text to generate a script that
> reindexes all the indexes in the right order:
> SELECT 'SELECT ''Reindexing index ' + name + ' on table ' + OBJECT_NAME (id)
> + ''''+ CHAR(13) +
> 'DBCC DBREINDEX(0, ''' + OBJECT_NAME (id) + ''', ''' + name + ''')'
> -- + CHAR(13) +
> -- 'DBCC SHRINKFILE(1, TRUNCATEONLY)'
> FROM sysindexes
> WHERE indid BETWEEN 1 AND 254
> AND OBJECTPROPERTY(id, 'IsMSShipped') = 0
> AND INDEXPROPERTY(id, name, 'IsStatistics') = 0
> ORDER BY OBJECT_NAME(id), indid
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Kay" <CallDBA@.hotmail.com> wrote in message news:%23qXB4f62FHA.3000@.TK2MSFTNGP12.phx.gbl...
>