Sorry to be a nob but my production database is current running as listed in the subject line. I have about 100 tables taking up almost 12.5GB. 99 of the tables use about 200 MB, the 1 table uses about 13GB of data. I have to assume that as data fills into the large table the data really starts to fragment within the database. This fragmentation obviosuly makes accessing the other tables slower than normal.
I have a question or two:
1) Is this really the case? Would the one large table adversly affect the smaller tables by placing data all over the disk (it's running RAID 0 + 1 I believe).
2) Is there a way to place the one table and it's indexes on disk and place the rest of the tables in it's own? If so, what is this called. It doesn't seem to be partitioned although this might be something that I'd like to do as well. I see how I can add files to the database but it only seems to use those files as extra space, not necessarily dedicating one table to a particular file.
My new request is I have enabled C2 Audit mode and wanted to delete old files that is more than 200MB. Could you Please give me a query ?. Thanks, Ravi
I'm trying to insert data into a table from two tables into a single table along with a hard coded value.
insert into TABLE1 (THING,PERSONORGROUP,ACCESSRIGHTS) VALUES ((select SYSTEM_ID from TABLE2 where AUTHOR IN (select SYSTEM_ID from TABLE2 where USER_ID =('USER1'))),(select SYSTEM_ID from TABLE2 where USER_ID =('USER2')),255)
I get the following-
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I hope someone can answer this, I'm not even sure where to start looking for documentation on this. The SQL query I'm referencing is included at the bottom of this post.
I have a query with 3 select statements joined together like tables. It works great, except for the fact that I need to declare a variable and make it a table within two of those 3. The example is below. You'll see that I have three select statements made into tables A, B, and C, and that table A has a variable @years, which is a table.
This works when I just run table A by itself, but when I execute the entire query, I get an error about the "declare" keyword, and then some other errors near the word "as" and the ")" character. These are some of those errors that I find pretty meaningless that just mean I've really thrown something off.
So, am I not allowed to declare a variable within these SELECT tables that I'm creating and joining?
Thanks in advance, Andy
Select * from
(
declare @years table (years int);
insert into @years
select
CASE
WHEN month(getdate()) in (1) THEN year(getdate())-1
WHEN month(getdate()) in (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) THEN year(getdate())
END
select
u.fullname
, sum(tx.Dm_Time) LastMonthBillhours
, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) lasmosbillingpercentage
from
Dm_TimeEntry tx
join
systemuserbase u
on
(tx.owninguser = u.systemuserid)
where
Month(tx.Dm_Date) = Month(getdate())-1
and
year(dm_date) = (select years from @years)
and tx.dm_billable = 1
group by u.fullname
) as A
left outer join
(select
u.FullName
, sum(tx.Dm_Time) Billhours
, ((sum(tx.Dm_Time))
/
((day(getdate()) * ((5.0)/(7.0))) * 8)) perc
from
Dm_TimeEntry tx
join
systemuserbase u
on
(tx.owninguser = u.systemuserid)
where
tx.Dm_Billable = '1'
and
month(tx.Dm_Date) = month(GetDate())
and
year(tx.Dm_Date) = year(GetDate())
group by u.fullname) as B
on
A.Fullname = B.Fullname
Left Outer Join
(
select
u.fullname
, sum(tx.Dm_Time) TwomosagoBillhours
, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) twomosagobillingpercentage
I am having various views and stored procedures in my database.During scripting the stored procedures/views is there any method or way to include [dbo].table_name used inside the views or procedures??
for example i have a stored procedure p_test. create proc p_test as select a.col1,b.col2 from table a join table b on a.col3 = b.col3
When i script out the procedure script should be in the following way.
create proc [dbo].p_test as select a.col1,b.col2 from [dbo].table a join [dbo.]table b on a.col3 = b.col3
Dear experts,If I have a number of related groups of data (e.g., stock prices fordifferent stocks) is it better to put them into many tables (e.g., onetable per stock) or into one big table (e.g., a single table where onecolumn is the stock id other columns are the price and other data)?The single table approach with a clustered primary key including thestock id and other information that is different for each stock seemscleaner to me. But I worry that having a single table could hurtpreformance when the database gets very large. The clustered primarykey should make queries on the single table fast, but I'm worried aboutinserts. According to my vague understanding of a clustered primarykey, records are physically stored on disk based on the primary key. Soif I insert a record for a given stock does the database have tophysicall "move down" all the records that are below that or does it dosomething smarter?To summarize:1. Should I use a single table or many tables?2. If using a single table, how are inserts handled by the DB toprevent inserts from getting slower and slower as more items are addedto the DB?Thanks in advance for your help and advice.
I have 3 tables, Type, Subtype, and Subtype2. All which are related by the ID of preceding table. Using a 3 textboxes and a button I want to insert new Types and subtypes to the tables. How do I go about identifying the new types new ID insert it in to the other tables? I am using ASP.net (vb) with sql server.
Hi All,I will like to create a table from two tables this (explained below) way using a stored procedure. Basically i want the stored procedure to return me the third table but i dont know how to do it.Table ATopicID Topic ----------------------------- 1 Sometopic 12 Some topic 23 Some topic 34 Some topic 4 Table BRateID Rate TopicID---------------------------------------1 5 12 5 13 5 24 4 25 4 36 3 5 Table CTopicID Topic Rate--------------------------------------------1 Some topic1 52 Some topic 2 5 3 Some topic 3 5Basically i have a table that stores topics associated with a particular subject. Those topics are stored in table A above. My users can just read the messages associated with the topic and rate that message. The rating is then stored in table B.Now i will like my users to search for topics with a particular word or sentence in table A and the topics that are returned have a rating they specify. My procedure takes the word or sentence to search in table A and and the rating which will be used in table B. I will like to construct another table that has this newly searched results and return it using a stored procedure or anything simple. I dont know how to do this because i have very little knowledge in stored procedures or sql..... Any help(Code) will be greatly appreciated...
I have an application that runs on several sites that has a table with 36 columns mostly ints och small varchars.
I currently have only one table that stores the data and five indexes and since the table on one location (and others soon) has about 18 million rows I have been trying to come up with a better solution (but only if needed, I dont think I have to tell you that I am a programmer and not an dba). The db file size with all the indexes is more then 10gb, in it self is not an problem but is it a bad solution to have it that way?
The questions are:
Are there any big benefits if i split it into several smaller tables or even smaler databases and make the SPs that gets the data aware that say 2006 years data is in table a and so on? Its quite important that there are fast SELECTS and that need is far more important then to decrease the size of the database file and so on.
How many rows is okay to have in one table (with 25 columns) before its too big?
Select: C1.firstname, C1.lastname, SP.lastyearsales, A.city From: SalesPerson as SP join Employee as E1 on Sp.salespersonID = E1.EmployeeID Right Join Employee as E2 on E1.EmployeeID=E2.EmployeeID join Address as A on E2.AddressID = A.AddressID Right Join Employee Contact as C1 on E1.ContactID = C1.ContactID
I've been tasked with the following: Export data from old table, to newly created table(s). I say tables because there's three destination tables total, and only two source tables. The two old tables are virtually the same, so the new table will be a combination of the two. More importantly I'll need to chop out some data from the old tables and create new details with them. As you can see, the old table was very "flat" in the sense that they kept adding new fields for bits of detail data (10 for one type of detail, 15 for another type of detail). I'd like to house that data in separate linkable tables. This is an example of the old and new data structure:
Im trying to bring together two tables into one, but they're records dont always match, so im getting akward returned records. So now i want to combine the fields i need from these two tables to create a new one. How would that be coded.
I want to
SELECT
[Customer_Bill_Customer_No],
[Customer_Bill_Customer_No],
[Sales_Header_Order_DateTime],
[Sales_Header_Your_Reference]
from
[NavisionReplication].[dbo].[Tbl_Sales_Header]
and SELECT [Sales_Invoice_Header_No]
FROM [NavisionReplication].[dbo].[Tbl_Sales_Invoice_Header]
I have 3 tables(Table1, Table2, Table3) and i want this 3 tables to be inserted/copied to NewTable. this is my query and it is good only for one table: INSERT INTO NewTable SELECT * FROM Table1;
when I'm in MediaImportLog , I want use column ImportSource to compare with column ChainCode in table BillerChain ( so I get BillerInfoCode) and then use the BillerInfoCode I got to compare with column BillerCode in Table Bill ( I get CompanyCode) finally I use CompanyCode to compare with column CompanyCode in table DataBackup so I can get the company's keepmonth How can I get the keepmonth? can I use parameters ?
How do I update a table's column, with the values of another tables column where the primary key between is Part_Number? table2 = temp_table Update Actuator_Components Set Scanned_Drawings = table2.Scanned_Drawings
Looking for some help here, so thanks for any input. I'm a painfully new newbie to SQL scripting.Situation: I have a simple database to handle an organization's events. Those events are categorized and may have more than one category assigned to each event. I need a maintenance Web Form to update their events.Set Up (so far): I have a CATEGORIES table. It has an auto incrementing UID and a Category name field. This table will be updated so infrequently, I plan to update it manually (no need for a maintenance Web Form). Next is the EVENTS table. It also has an auto incrementing UID along with several fields (Title, Location, DateTime, etc.). The junction table is named jEVENTSCATEGORIES. It has its own auto incrementing UID along with 2 fields named for the primary keys (UIDs) in the other 2 tables (EventsID and CategoryID).Goal: On the Web Form, I have a CheckBoxList control that's populated by the CATEGORIES table. One or more categories can be checked for each event. I have a FormView control that allows Edits and Inserts.Need: I need to know the INSERT statement(s) required to insert a new record in the EVENTS table and then to update one or more rows in the junction table (jEVENTSCATEGORIES).My Assumptions: I know how to create SELECTs and INSERTs and whatnot, but I'm not certain how to create a second INSERT statement that is based on a variable (or output) from a previous action. So any help would be MUCH appreciated. Thanks for your time!
I have 4 tables with the respective amount of records 1) 6755 2) 2021 3) 2021 4) 355
They all have the same columns. However, they need to be seperate, or at least when I query them. I'll be accessing this database via the web. i was first afraid that a large database would cause major slow down when accessing the db. So I broke it up into 4 tables. If I combined all 4 tables into one large table and just had a column that differentiated the 4, how significant would be the change in speed when accessing the table? It's not a big deal to keep them seperate, its just that when I have to add or remove a column from one table I have to remove it from all the tables. Furthermore, I'm using a module from DEVEXPRESS, don't know if anyone has heard of it, but when you use a gridview, it loads up the entire table even though your paging (which I think is retarded), so for that reason I was afraid it would slow up my access to the db. Any thoughts?
I am developing a Content management system of sorts and I want it to be pretty flexible. I have noticed that with web content (News, Articles, Events, FAQs) that there is a lot of similarity between these items. They all have the same basic fields: TitleSynopsisBodyStartDateEndDate (for News, Articles, FAQs start and end date can be used for content expiration. For events, they are used for the actual event dates.) But for some types of content, I will need fields specific to that type. For instance, I want to have a few custom settings for a "Photo Gallery" type, like, how many rows/columns of thumbnails to display per page.
I feel like I have 3 options, but would really appreciate your advice. I created diagrams for the 3 options, located here: http://nontalk.com/dbdesign/
How do I know when to use a table variable, and when to use a temp table in my stored procedures? It seems that in most cases table variables are more efficient (in terms of execution time / CPU usage) but some of my stored procedures perform an order of magnitute better with temp tables instead. Short of testing the stored proc both ways, how do I know what to do? declare @Temp table or create table #Temp
I have a few hundred users, maybe a dozen or two active at any given time, accessing the same database via ASP. The database has many tables, one being a very large orders table with a few million records, in which I have created a view against. A view only because I need to allow the user to filter quite extensively against the results. The users typically only need to view records for the last 30 days and results for each user might be five thousand records or less.
My question is this. Would I be better off writing each user's resultset to a temp table for that user's session and allow the filtering and sorting by the user go against that temp table and increase my hardware requirements to accomodate that. Possibly to the point of creating a database cluster. OR would I be better off leaving it as is where each users uses the same view.
FYI...each user may need visibility to only a hand full of fields, but over all the view must maintain many fields.
Any thoughts on this would be greatly appreciated. Thanks in advance.
I have a table variable into which I insert the results of a select statement. Based on the records held in the table variable I then want to update a field in one table and insert the records in the table variable into another table.
insert into @table(electionchangeid) values(1036276)
update electionchange set exportdate = GETDATE() from electionchange ec join @table t on t.electionchangeid = ec.electionchangeid
insert into @anothertable select * from @table
But does not work within my sp .... (see next post).
It doesn't generate an error. It just doesn't update or insert any records. I would think that it was a scope issue, except that I can do a select on the table variable and see that it does contain records.
I would be very interested to hear people's thoughts on this.
What's the best way to convert a large set of records from a simple schema where all fields are in one table to a schema where fields are split across two tables? The two table setup is necessary for reasons not worth getting into here.
Doing this via cursor is pretty straightforward, but is there a comparable set-based solution?
Here are sample create table commands. Obviously, the example below is simplified for discussion purposes.
-- One record from here will produce a record in TargetParentRecords and a record in TargetChildRecords for a total of two records. CREATE TABLE OriginalSingleTableRecords ( ID INT IDENTITY (1, 1) NOT NULL,
ColumnA VARCHAR(100) NOT NULL, ColumnB VARCHAR(100) NOT NULL,
CREATE TABLE table_name AS SELECT STATEMENT WHERE rownum = 0; this query will copy the table structure of one table without copying the data. I need to copy the table structures of all the tables in a particular database without copying the data.suggest me on this.
Player, Position, [From], [To], Fee, Type, ID, League, Window
I want to create a new table, EnglandFinal with all the data from the three tables although I'm guessing it would not be a good idea to copy the primary keys (ID column) as they would clash.
I have played around with CREATE and INSERT into and UNION but I get various errors. I'm sure I've done this before!
In SQL Server, I need to create a table from 3 different individual tables. I am new to the SQL Scene, so i want to know the best way to go about this. Each table has different fields, so that is making it difficult (at least for me). How about creating 1 table, that is composed of 3 other tables?
I know this is bad practice, but our District Manager wants to see production for his 'team' and whoever set this up back in the beginning gave each individual employee a different table, with custom fields (Why?!?!?!?!) so now I am trying to merge those 3 into 1, but want to get some insight on the best way to do this since there are different fields in each table and the merged (or master) table needs to have all of those fields.
I have to pick up a row from Customers and transfer it to CustomerMaster and CustomerDetails. CustomerId of CustomerMaster will be the CustomerId of CustomerDetails while transfer.
Hello,I'm not an expert in SQL, if you could help me for that littleproblem:I had tree simple tables with their fields:[Client] IdClient, Param[Sale] IdSale, IdClient, Param[Param] IdParam, ValueHow can I retrieve a recordset with this columns ?IdClient, IdSale, ValueOfParamClient, ValueOfParamSaleThe problem is that I can retrieve a Param for one table (Client orSale) like this request :SELECT Client.IdClient, Sale.IdSale, Param.ValueFROM(ClientINNER JOIN SaleON Sale.IdClient = Client.IdClient)LEFT JOIN ParamON Param.IdParam = Sale.ParamBut how can I retrieve the Param of the another table in a simplequery ? (because I would also like that it works for access)Thank for your help,Marc