I have a simple query which is taking about 2.5 minutes to execute. What can be done to speed it up ? I cannot change the table structure. even without the group by, and without the float and division, it takes about 2.25 minutes.
Select 'SV00302' as FileSource, [Service_Call_ID], sum(0) as ActualHours, sum(cast([Estimate_Hours] as float)/100) as EstHours, max(MODIFDT+Modified_Time) as ModifiedDateTime
Hello,I have created the following trigger:CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATEASDECLARE @foobar varchar(100)SELECT @foobar= foobar FROM insertedIF ( @foobar = 'foobar') INSERT INTO LogTable (LogText) values ('Found foobar')ELSE INSERT INTO LogTable (LogText) values ('Did not find foobar')GOBasically, the trigger monitors the values begin put in the foobar field,and acts accordingly based on what it finds. In practice, my needs are abit more complex (the trigger will be programmatically generated, based ona set of rules) but the principle is much the same.ErrorTable is defined as :create table LogTable (LogText varchar(128))UserDefinedFields is a table whose definition may change depending on theuser's needs, but for now assume it contains a varchar column calledfoobar.My problem is that if the user's needs change, and they remove the fieldfoobar, the trigger causes all subsequent inserts/updates to fail with anerror indicating the column foobar doesn't exist. (Which makes sense ofcourse!)CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATEASDECLARE @foobar varchar(100)if not exists (select * from syscolumns sc inner join sysobjects so on sc.id = so.idwhere sc.name = 'foobar'and so.name = 'UserDefinedFields') BEGININSERT INTO LogTable (LogText) values ('Error : Foobar column does not exist!')RETURNENDSELECT @foobar= foobar FROM insertedIF ( @foobar = 'foobar') INSERT INTO LogTable (LogText) values ('Found foobar')ELSE INSERT INTO LogTable (LogText) values ('Did not find foobar')GOI'd be happy with the above 'flavor' of solution (bailing, or logging anerror and bailing, when we hit unexpected problems) as long as theinserts/updates don't fail otherwise. Perhaps I can nest a transaction, orsupress a RAISEERROR or something?The cleanest solution would probably be to change a bunch of clientsoftware such that it won't remove the foobar field if this field isneeded for a trigger (foreign key constraints based on the set of rulesI'm using are a nice and intuitive solution). Unfortunately, that doesn'twork well with my timeframe (done by thursday) as changing the clientsoftware is impossible by then. Any ideas or suggestions? Platform isWin2k, SQL 2000 Enterprise (I think enterprise, certainly 2000).thanks,Dave
Say you have an existing populated SQL 2005 database, with 700+ tables, and you want to just change the order of the columns inside every table. Short of manually building conversion scripts, anyone know an automated way to do this? I was thinking thru ways to do them all in one shot, and have tools like Erwin and DbGhost that could be used also. Basically moving some standard audit columns from the end of the tables to just after the PK columns.
field ([idConteudo] [int] NULL) to ([idConteudo] [BigInt] NULL)
Or really should drop and create again?
CREATE TYPE [dbo].[tbProjeto] AS TABLE( [dsConteudo] [varchar](64) NOT NULL, [idConteudo] [int] NULL, [dtConteudo] [datetime] NULL DEFAULT (getdate()) ) GO
I have a database (MSSQL). To demonstrate the problem let me show a fictive Tablestructure. I don't want to discuss about how to save the data differntly, because the structure is fix and I can't change it.To get this result I would do a sql query with a lot of joins like that:
SELECT firstname, lastname, email.value, phone.value FROM Customer INNER JOIN ( SELECT Customer_Properties.id, Customer_Properties.value FROM Customer_Properties
[code]...
I don't think that this is really performant and the SQL-Queries get very complicated. Give it a other methode for that? I can't change the data structure.
hiI want to increase a varchar(5000)to varchar(8000) on a table thathas approximately million rows.....What is the impact on the serveror any good recomendations of a action to accomplish this in the best andfastest way.thanks davep
From last 1 week or so, i have been facing very strange problem with my sql server 2005s database which is configured and set on the hosting web server. Right now for managing my sql server 2005 database, i am using an web based Control Panel developed by my hosting company.
Problem i am facing is that, whenever i try to modify (i.e. add new columns) tables in the database, it gives me error saying that,
"There is already an object named 'PK_xxx_Temp' in the database. Could not create constraint. See previous errors. Source: .Net SqlClient Data Provider".
where xxx is the table name.
I have done quite a bit research on the problem and have also searched on the net for solution but still the problem persist.
we have a table in our ERP database and we copy data from this table into another "stage" table on a nightly basis. is there a way to dynamically alter the schema of the stage table when the source table's structure is changed? in other words, if a new column is added to the source table, i would like to add the column to the stage table during the nightly refresh.
Hi allI have two tables in SqlServer with Exactly Same Structure,I want to Copy all Records fromone of them to another one.I came across to "Insert....select..." statement But i have two problem 1) I don't know any thing about Columns name!!! i just know they have same structure and as far as i know , "Insert...select..." need the Column list to operate correctly, am i right? 2) these two table have One Prinary Key column with IDENTITY feature. Any Help Greatly appriciated.Regards.
Structure Number1 Category: CategoryId(P.K.), UniqueName, CreatedDate, ModifiedDateCategoryNative: CategoryId(F.K.), LanguageId(F.K.), NativeName, Description, Importance, IsVisible, CreatedDate, ModifiedDate Structure Number2 Category: CategoryId(P.K.), UniqueName, CreatedDate, ModifiedDateCategoryNative: CategoryNativeId(P.K.), CategoryId(F.K.), LanguageId(F.K.), NativeName, Description, Importance, IsVisible, CreatedDate, ModifiedDate Can anyone tell me that between above 2 structure what is better and why? I just add CategoryNativeId(P.K.) in Number 2 structure.
How can I setup a table structure for the diagram shown in the attached bitmap?
1) I need to create a product using labour and materials. 2) I need to create hardware using labour and materials. 3) I need to be able to include some hardware in some products. 4) Some materials in the product are made of a culmination of materials. E.G., Concrete is made of sand, stone, and cement.
Any suggestions?
So far I have :
USE NORTHWIND
Create Table tbProducts ( ProductID int NOT NULL, Product varchar(50) )
go
ALTER TABLE tbProducts ADD CONSTRAINT tbProducts_pk PRIMARY KEY (ProductID) GO
CREATE Table tbMaterials ( MaterialID int NOT NULL, Material varchar (50) )
GO
ALTER TABLE tbMaterials ADD CONSTRAINT tbMaterials_pk PRIMARY KEY (MaterialID) GO
CREATE Table tbLabour ( LabourCode char (2) NOT NULL, Labour varchar(50) )
GO ALTER TABLE tbLabour ADD CONSTRAINT tbLabour_pk PRIMARY KEY (LabourCode) GO
CREATE Table tbProductMaterials ( fkProductID int NOT NULL, fkMaterialID int NOT NULL, Quantity Float NOT NULL )
GO ALTER TABLE tbProductMaterials ADD CONSTRAINT tbProductMaterials_pk PRIMARY KEY (fkProductID, fkMaterialID) GO
I'm new in creating tables. and I was asked to create table(s) to capture information using SQL server 2005 (express edition)
please read below and share your thoughts and opinions o what's the efficient and best way to structure the tables.
I need to capture user's input daily and every hour, text can be from 20-100 characters, and my company is expecting to have 50,000+users in the future...Also the hrs's text can be stored for max 120 days, after that data would be deleted from the table(s) An example is put all together, (not sure if it is the right and efficient way)
An example is put all together, (not sure if it is the rigth and effectient way) and if database would support that.. and if it will be fast enougth to search for data
(table structure) - (example with 3 users) userId | timestap | message 1 12/12/2007 10:00 some message 1 12/12/2007 11:00 some message 1 12/12/2007 12:00 some message 1 12/12/2007 13:00 some message 1 12/12/2007 14:00 some message 2 12/12/2007 10:00 some message 2 12/12/2007 11:00 some message 3 12/12/2007 12:00 some message 3 12/12/2007 13:00 some message 3 12/12/2007 14:00 some message ...etc..
Hi,I am new to XML and need a structure of table in XML format, which needsto be created as a table in another server.The Source and destinationservers are SQL Server 2000. Could anyone help me on this.Balaji.S.--Posted via http://dbforums.com
Hi, I have one field "Status" with 15 different types of values. Like 1, 2, 3, 4 .. 15. Now this Status field contains the values like this: Id Status 1 1,2 2 3 3 1,2,3 4 13,15
What is the best way to organize this information in SQLServer table? My idea is Create one table with the following volumns: ID, Status1, Status2, Status3, ... Status14, Status15.
Now the above data look like this: Id Status1 Status2 Status3 ... Status13 Status14 Status15 1 1 1 0 0 0 0 2 0 0 1 0 0 0 3 1 1 1 4 0 0 0 1 0 1
So, In future If they add new column they can easily add column like status16. And status table look like this Status StatusID Description 1 a 2 b .. 15
All,On my aspx page i have 2 sets of checkboxlists, each with a number of items and i am storing that info in my db. currently i have my table set up this way: InfoID--PK autoUserID-intCheckBoxList1ID-intCheckBoxList2ID-int So a user can select more than 1 item in each checkbox, so this table will contain multiple user-ids and each id from the respective checkboxes. My question is, is there a better way to store this data? I hope this is clear, any input would be greatly appreciated.Thank you.
Hi,I have a table for storing my picture albums here it is:CREATE TABLE [UserAlbum] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [UserID] [int] default(0) , [AlbumName] [nvarchar] (100) NULL , [Audience] [int] default(0) , [Date_added] [smalldatetime] NULL , CONSTRAINT PK_CmmNet_userAlbum_ID PRIMARY KEY CLUSTERED ( ID )) ON [PRIMARY]GO it has a field called "audience" as the name defines i want to choose who will see my albumsit is integer and as follows:0 value=everyone1=friends only2=private as i started to write a query for it i came into this problem: for exampleif i write SELECT * FROM UserAlbum where audience=1 then only friends can see the infowhat happens to everyone with value of 0?when i set it to 0, friends should also be able to see the info because it is set for everybody i noticed i should use "in cluase" like thisSELECT * FROM UserAlbum where audience in ('0','1') > so in this way both everyone and also friends can see the info or maybe i should add 3 different fields for private,public,friends it seems to be simple but at the same time harddoes anyone have a suggestion?
Hi i have a student table and also an societies table, and a student can belong to as many societies as possible, for example student John Taylor belongs to the Football society, rugby societey and dance society, where as student Jim Jenkins belongs to the Football society, rugby society, arts society and graphics society. My tables so far look like this; STUDENTS; student_id, student_name SOCIETIES; society_id, society_name
My question is how can i make the scenario above reflect in my table structure, would i need to create another table, if so what fields or columns should i place in this new table, thank you.
I'm a VB.net programmer working in an environment that doesn't have a true sql db administrator. We have a situation where we're thinking about adding a new database (db2) with the same Tables used in an existing database (db1). We were hoping to avoid this, but circumstances are forcing us to think about it. Are there any sql tools out there to maintain a dual-db like this? What are the main disadvantages to this?
Hello I have replicated 1 database.Now i need to change the datatype length of one feild from varchar 12 to varchar 20.But when i try to do that it shows error ODBC error !Cannot modify database because it is in replication mode. Can any body help me to sort out this problem. Thx Bilal
Hi, I'm looking for some code that will pull back a list all tables in a database that meet a certain requirement - in this case all tables that have an identity column.