Dynamically Generating CREATE INDEX Statements
Feb 15, 2001
Does anyone have any SQL that will look at a DB and dynamically generate CREATE INDEX statements? I
know I can use EM but I want to make this a scripted process and you can only generate CREATE INDEX statement if
you script out the tables too.
Any Ideas??
Thanks
View 2 Replies
ADVERTISEMENT
Nov 24, 1999
Hi,
I need to regenerate a large view each month which performs a union across a number of partitioned tables. (DB is SQL Server 7)
The select statement for each table within the union is large and cannot be replaced with 'select *'.
One possible approach is to obtain the current view definition from syscomments and append an additonal 'UNION select ... from ...' to the end. However I'm having difficulties getting the full textual definition back into variables with the stored procedure. Getting the view definition from the information schema returns a truncated version.
Is there a way to get the whole of the description back (may be >8k)?
I have similar problems manipulating large text fields within the stored proc. If I try to build the entire view definition each period I hit the problem that EXEC cannot take a TEXT parameter (and a varchar isn't big enough).
There are some (messy) ways around this problem, but has anyone had a similar situation where large statements have have to built up before passing them to an EXEC statement and found a neat solution?
View 1 Replies
View Related
Feb 8, 2006
Hello all. I need to build a barcode and stuff it in a image control at runtime in SRS. I have the code at it works perfect for webforms etc but not in the actual SRS report itself. In SRS I put the code in the report properties code but it blows up on bitmap, graphics etc so I added the system.drawing and system.drawing.imaging namespace and it still fails with the same error. I'm certain there is a simple fix for this and would greatly appreciate anyones assistance in making this happen.
Error:
There is an error on line 15 of custom code: [BC30002] Type 'Bitmap' is not defined.
Environment:
Visual Studio 2003
SQL Server 2000 SP4
SQL Reporting Services
Code (apologies in advance for the formatting):
private function getBarcode(input as string)
Dim ValidInput As String = " !" & Chr(34) & "#$%&()**+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~" & Chr(0) & Chr(1) & Chr(2) & Chr(3) & Chr(4) & Chr(5) & Chr(6) & Chr(7) & Chr(8) & Chr(9) & Chr(10) & Chr(255)
Dim ValidCodes As String = "17401644163811761164110012241220112416081604157214361244123014841260125416501628161417641652190218681836183018921844184217521734159013041112109414161128112216721576157014641422113414961478114219101678158217681762177418801862181418961890181819141602193013281292120011581068106214241412123212181076107415541616197815561146134012121182150812681266195619401938175817821974140013101118151215061960195415021518188619661724168016926379"
Dim Digit As Integer = 104
Dim i As Integer
For i = 1 To input.Length
Digit += (i * InStr(1, ValidInput, Mid(input, i, 1)))
Next
Digit = Digit Mod 103
input = Chr(9) & input & Mid(ValidInput, Digit, 1) & Chr(255)
Dim bmp As Bitmap = New Bitmap((input.Length * 11) + 13, 50)
Dim g As Graphics = Graphics.FromImage(bmp)
g.FillRectangle(New SolidBrush(Color.White), 0, 0, (input.Length * 11) + 13, 50)
Dim p As New Pen(Color.Black, 1)
Dim BarValue, BarX As Integer
Dim BarSlice As Short
For i = 1 To input.Length
BarValue = Val(Mid(ValidCodes, ((InStr(1, ValidInput, Mid(input, i, 1)) - 1) * 4) + 1, 4))
If BarValue > 0 Then
Digit = 11
If i = input.Length Then Digit = 13
For BarSlice = Digit To 0 Step -1
If BarValue >= 2 ^ BarSlice Then
g.DrawLine(p, BarX, 0, BarX, 50)
BarValue = BarValue - (2 ^ BarSlice)
End If
BarX += 1
Next
End If
Next
bmp.Save(Response.OutputStream, ImageFormat.Gif)
Best regards,
TKAP
g.Dispose()
bmp.Dispose()
end function
View 1 Replies
View Related
Apr 20, 2006
My problem is this: How do I dynamically generate a Report Model Definition with c#?
Is there some sort of method I could call from the ReportingService2005 web service? Or some sort of APIs I could use?
If I didn't have a dynamic database structure, I would just create a Report Model Definition with BIS and then deploy the same model to each customer. However, our product creates additional tables in the database, depending on what data users wish to collect.
There are currently 2 solutions for this problem. First, I can manually create a Report Model Definition through the Buisness Intelligence Studio (BIS). However, I wish to be able to dynamically generate the report model without having to go through BIS. Second, I could use C# and manually write the XML of the SMDL. However this seems problematic.
I'm really hoping for some MS API that I'm missing out on here. Thanks for the help.
- Sean
View 9 Replies
View Related
Mar 3, 2014
I created a cursor that moves through a table to retrieve a user's name.When I open this cursor, I create a variable to store the fetched name to use within the BEGIN/END statements to create a login, user, and role.
I'm getting an 'incorrect syntax' error at the variable. For example ..
CREATE LOGIN @NAME WITH PASSWORD 'password'
I've done a bit of research online and found that you cannot use variables to create logins and the like. One person suggested a stored procedure or dynamic SQL, whereas another pointed out that you shouldn't use a stored procedure and dynamic SQL is best.
View 3 Replies
View Related
May 20, 2008
Hello all,
I have a few questions relating to scripts and I'm looking for some help, or at least a point in the right direction.
1) I'm generating CREATE scripts to move a number of tables/procedures/functions from my testing database to my production database. The issue I have is the script doesn't seem to be generated in a particular order, so I'm getting errors when a table/procedure/function is created that references something that hasn't been created yet. Is there a setting available to create the script in a specific order to prevent these errors?
2) This is somewhat related to the first question. I need to drop all the tables/procedures/functions before I re-create them. Can I set all the DROPs at the beginning of the script, and then run all the CREATEs?
3) Eventually the database will be ready for production and in use. And eventually I'll be asked to make changes, without erasing existing data. Can I accomplish this using the generate scripts feature? What topics should I be investigating when looking into conducting these types of updates? "Updating database" is too general and I'm not sure the technical term. I've done very simple DB-related tasks so I'm trying to figure out what I'm looking for so I can educate myself. Basically, I don't know what I don't know.
Any help is appreciated. Thanks.
View 1 Replies
View Related
Jun 10, 2007
Hi,
I am new to SQL Server and need your help.
I have a table (old_table) with about 500 columns and each column of type varchar. I have to generate a table (new_table) which has all the columns of the old table but with different data types.
Is there a way I can use the syscolumns to generate a “create table� statement?
Thanks.
View 4 Replies
View Related
Dec 5, 2007
Dear All.
We had Teradata 4700 SMP. We have moved data from TD to MS_SQL SERVER 2003. records are 19.65 Millions.
table is >> Order_Dtl
Columns are:-
Client_ID varchar 10
Order_ID varchar 50
Order_Sub_ID decimal
.....
...
..
.
Pk is (ClientID+OrderId+OrderSubID)
Web Base application or PDA devices use to initiate the order from all over the country. The issue is this table is not Partioned but good HP with 30 GB RAM is installed. this is main table that receive 18,0000 hits or more. All brokers and users are using this table to see the status of their order.
The always search by OrderID, or ClientID or order_SubNo, or enter any two like (Client_ID+Order_Sub_ID) or any combination.
Query takes to much time when ever server receive more querys. some orther indexes are also created on the same table like (OrderDate, OrdCreate Date and Status)
My Question are:-
Q1. IF Person "A" query to DB on Client_ID, then what Index will use ? (If any one do Query on any two combination like Client_ID+Order_ID, So what index will be uesd.? How does MS-SQL SERVER deal with these kind of issues.?
Q2. If i create 3 more indexes on ClientID, ORderID and OrdersubID. will this improve the performance of query.if person "A" search record on orderNo so what index will be used. (Mind it their would be 3 seprate indexes for Each PK columns) and composite-Clustered index is also available.?
Q3. I want to check what indexes has been used? on what search?
Q4. How can i check what table was populated when, or last date of update (DML)?
My Limitation is i Dont Create a Partioned table. I dont have permission to do it.
In Teradata we had more than 4 tb record of CRM data with no issue. i am not new baby in db line but not expert in sql server 2003.
I am thank u to all who read or reply.
Arshad
Manager Database
Esoulconsultancy.com
(Teradata Master)
10g OCP
View 3 Replies
View Related
Nov 7, 2005
Anyone know an easy way to generate the SQL Scripts to gererate the
tables/sp's/triggers/indexes/fk's, ect? I know Sql Server 2000 lets you
generate the db script, but I don't know how to do this with 2005
View 2 Replies
View Related
Jul 20, 2005
Can I dynamically (from a stored procedure) generatea create table script of all tables in a given database (with defaults etc)a create view script of all viewsa create function script of all functionsa create index script of all indexes.(The result will be 4 scripts)Arno de Jong,The Netherlands.
View 1 Replies
View Related
Feb 11, 2014
Other than right-clicking on each individual table in SSMS and generating a CREATE script, is there a simple way to generate CREATE TABLE scripts for tables within a given database?
Background: I have a bunch of tables in one database, and I would like to add tables to a second database that have the same names and basic structures of some of the tables from the first database.
I do not need to transfer any data from the tables, this is a seperate project that will use a similar data structure. I just want to generate the CREATE TABLE scripts for 30ish tables within the first database, and then I'll tweak the scripts as appropriate and run them against the new database.
[URL] ....
View 7 Replies
View Related
Sep 2, 2005
Hello,
I am trying to create a sp dynamically. However each time, I run my sp, which creates the dynamic SQL for the sp, then it automatically changes:
CREATE PROCEDURE .....
to
Alter PROCEDURE ....
Then I am obvoiusly getting the error msg:
Invalid object name.
How can I get rid of that?
View 14 Replies
View Related
Sep 12, 2007
Hi! I am using VS 2003 (v 1.1)
I need to generate tables with the values from the Backend (SQLServer 2000) database in C#.Net.
How can i create the tables, tablerows, cells, etc. from the codebehind page of C#. I am having a very little knowledge about dynamic generation.
Give me the complete code with can example (if possible)
Thanks & Regrads
Jai Shankar
View 1 Replies
View Related
Apr 14, 2008
Hi,
I have N1 table where columns name(id,Field). Base on the fields of this table I want to create N2 table from SP where data from N1 will be columns in N2.
id Field
-- ------
1 ID
2 First
3 Last
Create table N2(ID,First,Last)
regards,
Mark
View 6 Replies
View Related
Oct 7, 2006
I'm currently developing an RDF application which need to handle lots of datatypes. But I want to use SQL-Servers capabilities for efficient querying and sorting. Therefore, I've wanted to create a Main Table which stores a Reference to the Table where the Data is stored. The Data itself should get stored in a Datatype-specific Table.
The Typed Table might get created by something like:
public void CreateTypedLiterals(Type type)
{
String sql = String.Format(
"CREATE TABLE [Literals_{1}] (" +
"ID int DISTINCT NOT NULL, Value {1})",
// BUG: does not work
// WARNING: introduces a potential sql-injection problem
type.ToString()
);
...
As you can see on the statements this solution makes many troubles. So I've wanted to implement it in a more fine way using a DataTable:
[SqlProcedure]
public void CreateTypedLiterals(Type type)
{
DataTable TypedLiterals =
new DataTable(
String.Format("Literals_{0}", type.ToString()));
TypedLiterals.Columns.Add(
"ID", typeof(int), "DISTINCT NOT NULL");
TypedLiterals.Columns.Add("Value", type);
...
But I have totally no Idea how to fetch this result into the existing Database. It might be cool to simply access the Database as it would be a .NET Dataset in the form:
using(Microsoft.SqlServer.Server)
{
CurrentDatabase.Tables.Add(TypedLiterals);
}
But this is afaik not possible. Has anybody an idea how to solve this issure?
View 5 Replies
View Related
Apr 3, 2007
I am trying to dynamically create subtotals base on values in a column. I also have to group by year. I have gotten the group by year. I used the (previous function) to check for the year and col1 not being equal. I am getting the first subtotal back, don't know how to proceed in my function to return the remaining subtotals
i.e.
col1 col2 col3
aaa 111 2005
bbb 222 2006
aaa 333 2006
ccc 444 2005
ccc 555 2006
bbb 666 2006
bbb 777 2006
ddd 888 2007
2005
aaa subtotal: 1
ccc subtotal: 1
total: 2
2006
aaa subtotal: 1
bbb subtotal: 3
ccc subtotal: 1
total: 5
2007
ddd subtotal: 1
total: 1
grandtotal:
aaa 2
bbb 3
ccc 2
ddd 1
totalnumber 8
View 1 Replies
View Related
May 3, 2008
Hi there!
I have a certain scenario and would like to know if it would be recommendable to try and realize it through RS.
I have a matrix of sales data (countries, regions, categories, total sales, Year-To-Date, changes, etc.) that need to be shown on charts. The charts themselves have a single format (bars). The out put needed is a relatively large number of charts (3000+) that would allow for a great number of comparisons (country to country, region to region, etc.). All these charts share a single layout. What would be varying greatly are the values and the labels attached to the elements on the chart (labels of the bars, title of the chart, legend, footnotes, etc.)
My plan is the follwoing:
- create a .net module that would prepare the data for the chart. This would be done with two tables
- parent table with general information
- child table with the the values for the bars and the labels
- Create a parametrized report in RS that accepts the Id of a report from the parent table
- Call this report for each and every report that can be found in the parent table
I would really appreciate any information of the feasabilitiy of this plan. I have worked a lot with Crystal before, but I don't have it anymore and will be using RS from now on. I haven't really started working with RS as of yet, but would need to know if this is "doable" with RS!
Thank you very much in advance for your replies!
Greetings
NB
View 5 Replies
View Related
Sep 5, 2014
I am having SP which gives, two result sets. The columns which are coming from result sets are also dynamic.
i.e. some time 5 columns and some time 10 columns.
Now I want to load this output into 2 different tables on daily basis. This would be truncate/delete table and load again.
Now my problem is that as I am not sure about columns, Is it possible to create table(Physical Table) depends on output of SP, and after load data into it.
During each load we can drop table, No issue and we can handle this through SSIS Package.
View 2 Replies
View Related
Jun 2, 2008
Hi,
There is a table exists in a database, I have to write a stored procedure to create the same table in different database, with the same column name and field. This should be done in runtime. Is it possible. The table will be passed as a parameter to the stored procedure.
View 3 Replies
View Related
Nov 2, 2006
I have a need to create a database, and then populate it. However, thecode below doesn't work as I hoped it might (it creates the table inthe "master" database, which is Not A Good Thing). I know already(thanks Tony!) that if you use Dynamic SQL for the USE command, thenthe subsequent operations need to be Dynamic SQL as well, which is apity since there are over 11,000 lines of it and I don't really fancydebugging it!Does anyone have a cunning plan? In a nutshell, I would like to beable to:1. Create a new database with a derived name - as in the case below aname based on the year, though it might be month as well.2. Create and populate tables in this new database.These operations would ideally be running from a scheduled job.Any thoughts?TIAEdward====================================USE MASTERDECLARE @DBName VARCHAR(123)SET @DBName = 'MyTest_' + CAST((Year(Getdate())) AS Varchar)if not exists(select dbid from master.dbo.sysdatabases where name =@DBName)exec('CREATE DATABASE ' + @DBName)elseraiserror('Database already exists.',3, 1)EXEC ('USE ' + @DBName)if exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[TestTable]') and OBJECTPROPERTY(id, N'IsUserTable')= 1)drop table [dbo].[TestTable]GOCREATE TABLE [dbo].[TestTable] ([TestID] [int] NOT NULL ,[Description] [varchar] (50) COLLATE Latin1_General_CI_AS NULL) ON [PRIMARY]GO
View 3 Replies
View Related
Apr 29, 2008
Hi,
how to dynamically create columns for a table
View 2 Replies
View Related
Oct 8, 2007
Hi,
I need to dynamically create a script component (by code).
Is it possible?
Thanks ahead,
Eran
View 6 Replies
View Related
Oct 27, 2006
I need to get a list of customer ids and then use them as a parameter to select from a transaction table and then create a file for each customer. I have used an execute SQL task to get the list of customers and have put the result set into a variable.
How do go through the recordset to create a file for each customer?
View 1 Replies
View Related
Apr 10, 2008
hi,
Can you guys please give me the steps of how to create a destination file dynamically. What i mean is for example i want to get everything from a table and ssis should create a file distination according to today's date and save it in a specific folder.
thanks
View 7 Replies
View Related
Dec 6, 2007
I have a parameter in my report with 2 options.
1."Less than Jan 1 2007"
2."Greater than Jan 1 2007"
According to the option selected, I should have the query look like:
1."Less than Jan 1 2007"
select * from table_name
where open_date < Jan 1 2007
or
2."Greater than Jan 1 2007"
select * from table_name
where open_date > Jan 1 2007
Please let me know how can I acheive this.I'm Using ORACLE database
View 3 Replies
View Related
Jun 25, 2015
Log-in access web-page.When page is accessed a stored procedure is executed that will provide a list of all the RA(Problem -- when a new building is added, this stored procedure must be opened and syntax added)..Results are stored in a drop down list on the page.Create a table holds list of all buildings something similar to this
Create Table [dbo].[BuildingInformation] (
ID INT IDENTITY NOT NULL,
BuildingName varchar(50),
RAName varchar(50)
[code]....
Alter the stored procedure so that when it is run it will iterate the BuildingInformation table and compare the value in BuildingInformation to the values in the field BuildingName of the view [RA]. If all buildings contained in the table [BuildingInformation] exist in the view [RA] nothing will change. If their are values in the [BuildingInformation] table that do not exist in the view [RA], the view [RA] will be dropped and recreate with a 'Union ALL' for each building in the table
View 6 Replies
View Related
Oct 23, 2007
I' m using Microsoft Reporting. Is there a way to create Report .rdlc file Dynamically on the fly? I' m using VB.net.
Any help can be appreciated.
Thanks
Mythili
View 9 Replies
View Related
Apr 19, 2006
I am new to writing SQL code and I read that you can use ALTER statements to create an index for a table. How would I go about doing that? Everything that I have tried in Query Analyzer comes up with an error.
Any help is appreciated.
View 3 Replies
View Related
Jan 27, 2007
I have some problems getting my SSIS package to run in a transaction, I wonder if anyone can assist.
What I want to do is run one package, which consists of a
- 1) create staging table SQL statement
- 2) read (all) from Access MDB to staging
- 3) copy (only new) from staging table to real table
- 4) drop the staging table
I changed the package to "require" a transactions, and left all containers in it to "supported" (default, I think). I left all the transaction type to default "serializeable".
The package does not work, since the table I created on step one is not "seen" when step 2 wants to insert into it. If I set the package transaction back to "supported" (default) the package works, but an error on step 2 or 3 will not rollback changes and not remove the staging tables...
So, my question really is: How do I make step 1 results visible to step 2 in the same transaction? Or do I need to take a completly different approach for this?
Stupid question I think, but I seem to not be able to find the right way to handle this situation...
Thanks for reading!
Ralf
View 4 Replies
View Related
Oct 5, 2007
Hi
I have written stored procedures to create a database with db name as input parameter
I need to create a batch file to run the stored procedure with input value given in the command prompt along with the batch file will be my dbname, which will be used by the stored procedure to create the databse.
and also few sql statements to insert data into those tables after creating
Plz could any one help me out to create code to create a batch file
thanks in advance
View 4 Replies
View Related
Feb 28, 2005
I am having problem with 'TOP @pageSize'. It doesn't work, but if I replace it by 'TOP 5' or 'TOP 6' etc., then the stored procedure runs without errors.
Can someone please tell me how I could use @pageSize here so that it dynamically determines the 'n' of 'TOP n' ?
ALTER PROCEDURE dbo.spGetNextPageRecords
(
@pageSize int,
@previousMaxId int
)
AS
/* SET NOCOUNT ON */
SELECT Top @pageSize ProductId, ProductName
FROM Products
WHERE (ProductID > @previousMaxId) order by ProductId
RETURN
View 4 Replies
View Related
Jan 28, 2006
Is there a way to dynamically create a connection manager @ run time? I would like to do this from a data set of connection strings so I can link them into a union all component.
View 1 Replies
View Related
Nov 19, 2007
Hi,
I have a sproc that returns somevalues and everything is working fine... and in my reports i am assigning the header data (in a detail column) based on the some feilds in the sproc... and there around 20 feilds that i want to show... but at a given time i am pretty sure that there wont be more than 10 fields that will have data.
So is it possible that show only the columns that have data in it and sometimes if there is less that 5 - 6 fields.. i want to realign the widths in those tables..
any help is appreciated..
Regards
Karen
View 9 Replies
View Related