In a project with SQL Servcer 2005 the customer is interested to save (archive) content of a table frequently. They want to have possibility to restore the table content as before. I have suggested to export the table every day to a text file and save the file in Visual source safe. If they need there will be possibility to import the text file later. Now I wonder, is there any other way to do archiving of the table content in SQL Server 2005?
I faced problem related to Locking and Isolation Level on Table(s).
My problems is there r some tables which r frequently updated, and I also want to fire select query over those tables every 1 seconds and want to get only committed records. In current scenario we start transactions with ReadCommitted Lock for updating records. But in this scenario I can€™t get select query result because of some of recourses r used by transactions so after some time it gives Deadlock error.
So I want solution like both operation run simultaneously and get only committed records at a time of transaction running Please help me for solving my problem.
I have a table called customers that store information about the particular customer. I would like to have a table called Archive so that when I delete a Customer that have not been active for a specific time then the deleted information will be automatically be inserted into the Archive table. Do I need to create the archive table with the same numbers of columns as exactly as the customer table?
I need some basic idea about how this should be implemented.
The purchased-application mssql 6.5, sp 4 that I am working on has one large table has 13m illion. It the largest table considering thenextlatgest table is only1.75 million rows.
Thew vnedor has made a change to this largest table in recommending changing a data type -- char to varchar. To make this change easier to do, I want to "archive" older data not necessary for the current year or current processing to another table.
What is the best way to do this archiving?
Any information you can provide will be greatly appreciated. Thanks.
I currently have one table that lists all projects and tasks within the organisation. One of the table fields is the task status, open or closed. I would like to be able to have a process by which the tasks that are completed are removed from the table and placed into another (archive) table. The same records then being removed from the original table. which then only contains the incomplete tasks. This process could be run at given times during the day or at the point when the status of a task is changed from open to closed, either way each time the process is run it would need to append the rows removed into the archive table. Anyone any ideas on the best way to do this?.
I have two tables say A and Archive. After a certain period of time some records are to be sent to archive table.To copy records to archive table I am using SqlBulkCopy operations.Now I have to delete the records from A Table. I was thinking of sending a Comma seperated id's of rows that are to be deleted to a stored procedure.Are there any better techniques to move data to archive table and to remove data from main table.?Thanks.
I have these two tables Log and CategoryLog, I need to archive records older than 13 months in these two tables to two separate tables and then delete the archived records from Log and CategoryLog tables. The problem is that only 'Log' table has a date column, the other table CategoryLog does not have any date column. But the two tables are connected by a column(LogID). How to archive the data and then delete the archive data from both tables.
The problem is, I have a table with one column of varchar(8000) datatype. It has got 1000's of records. Through Query Analyzer, I am not able to view my records after 257 columns in my table, even I increased my textsize by using 'set textsize' command.
Any other setting is available to correct this. Any help is appreciated.
I have a particular production database that on a few recent occasions has suddenly had one of it's tables empty of content. Now there are no jobs or triggers in place neither is any stored procedures that could perform a delete or alter table operation in place. The permissions have been set not to allow this either. The datatype is text only. What is intriguing is the QA server has an exact mirror and this dosen't happen. Has anyone come across this sort of phenomenon?
I have a table having XML column. I want to read a XML document and insert content of the XML file into this xml column. CREATE TABLE [XMLTest]( [DataAsXML] [xml] NULL,
[CreatedDate] [datetime] NULL )
I have tried the following query declare @filepath varchar(100)
declare @filename varchar(100)
set @filename = 'Referred'
set @filepath = 'D:ReportOutput'+ @FileName +'.xml'
print @filepath
insert into XMLTest
SELECT xCol,getdate()
FROM (SELECT * FROM OPENROWSET
(BULK @filepath,SINGLE_BLOB) AS xCol) AS R(xCol)
Problem is that When I give complete file path for BULK instead of variable name i.e. BULK 'C:Test.xml', query runs fine. But when I try to use @filepath, I get error "Incorrect syntax near '@filepath'." What am I doing incorrect? Also,If some one can suggest a better approach to load content of XML document to table?
Hi all,need advice on the following task:copy the content of a big table from DB_A to DB_B in the same serverthe size of table:~ 7 million rows, ~ 9G in size, 1 clustered pk index, 13 nonclusteredindexcurrent practice:use DTS to copy the data, takes over 20 hours as-- first had to delete existing data of the table in DB_B-- then copy-- all these happen while all indexes are in place.I am trying to check what is the best or most efficient way to copythis kind of data and what wouldbe the expected time for such load.my machine: SQL 2000 Enterprise, 8-way P4, 12G RAM on a EMC Clarrion600 SAN.
I keep product name, id in Table1. I keep Category name, id in Table2. I keep relation between product and category (product_id, category_id) in Table3. I have added some products to the table with proper category. Work fine But for some products I did not specified any category (ie their id is not present in Table3) But now I want all such products (ie all products whose category is nothing) To be associated with category_id 10
I was able to view table content easily before, but after Ireinstalled everything, I cannot find the option to view table contentin MS SQL Server Express. I can define table with no problem. Checkout the screen snapshot below, from which you'll see that the popupmenu frrom right-clicking on the table name does not have the "Opentable" option. What is going on?http://farm1.static.flickr.com/167/...839620d0b_o.png
1 Banana2 Orange3 Apple Order tblOrder, tblOrder: CustID; ProductID; Amount
1 ;2 ;$20 – means Peter ordered $20 oranges
How do I write the SQL query so that the values in tblProduct become column, currently I have 20 items in that table. So, it will return something like this according to the information that I provide above?
I want to export data in a table from one database to another database. And I would like it bo be clone of the source table, if it's possible. Is there any tools out there that can help me with this or do I have to write my own code?Is it possible to query the database to get all columns and datatypes for å requested table? If possible, can you give me an example?If I have to write a tool myself I guess I would do something like this: Export - Query the database for columns and datatype for the requested table. Dynamically generate a query to retrieve all rows from the table and save it to an xml file. Import - Turn off the Identity Increment, loop through the xml file and generate insert queries to insert a clone of each row, turn off the Identity Increment. Viola! If programming only could be that simple :-) Regards, Sigurd
Hi we have a table with about 400000 records in it. It starting to take longer and longer to add a new record. I was thinking of creating another identical table and archiving off most of the records every month (we are now adding about about 4000 records a day) . Is this the best thing to do? I don't know a lot about sql server so any help or suggestions would be great
Hi,I use view to join difference table together for some function. However,when the "real" table fields changed (e.g. add/delete/change field). Theview table still use the "old fields".Therefore everytimes when I change the real table, I also needed open theview table and save it by SQL enterprise manager manually for update theview table field.Can we use a SQL command or other method to update it directly?Regards,Silas
I'm struggeling for more than a week now with this problem, without a finding the solution.
I have two databases, MS Access and SQL Server 2005 Express Edition
Using a procedure in Visual Studio i would like to copy all the records from one table in MS Access into an existing table in SQL Server (the tables have the same name and the same layout)
I tried to prepare one Dataset to copy from Access into SQL Server but when i run the command 'DaSQL.Update(DsSQL, "Tabella") nothing happens (not even an exeption has been raised), looking during debug, the DataSet seems filled though...
Please could anyone explain what's wrong and / or is there a more quicker way to copy data from a table to another?
Note i woul have as a final goal to get data from an AS400 database by ODBC, manage it, and put it on SQL Server for a 'data mining' scope (eliminating the use of MS Access, not suited for FE-BE).
the procedure goes like this;
' Create a connection to the MS Access Database Dim connectionToAccess As New OleDbConnection(DBConnectionAccString) strsql = "SELECT * FROM [TABELLA]" connectionToAccess.Open() Dim DaAccess As New OleDbDataAdapter(strsql, connectionToAccess)
Dim DsAccess As New DataSet("ACCESS") DaAccess.FillSchema(DsAccess, SchemaType.Source, "Tabella") DaAccess.Fill(DsAccess, "Tabella")
' Create a connection to the SQL Database Dim connectionToSQL As New SqlConnection(DBConnectionSQLString) connectionToSQL.Open() Dim DaSQL As New SqlDataAdapter(strsql, connectionToSQL)
Dim DsSQL As New DataSet("SQL") DaSQL.FillSchema(DsSQL, SchemaType.Source, "Tabella") DaSQL.Fill(DsAccess, "Tabella")
I have a query that retrieves a single record from searching on two tables. The statement goes like this... select sum(amount) from Table1 A union Table2 B on a.id = b.id where date < ### and date > #### and account = ###
As people are running a particular report, this statement is executed time and time again to pull up the numbers necesarry for the report. When the report gets slow, I can speed it up by updating the statistics. My concern is that I'm having to update the statistcs every hour; otherwise, the query becomes slow. I have noticed that users are inserting data while users are running the report on one of the tables listed above. I'm sure that's making it become more fragmented and ultimately slowing down the query. Do you have any suggestion on how I can make the union of these two tables faster? Or is there anything I could do to speed the query besides creating clusted indexes? Any help would be appreciated....thank you
We have a table which needs to be updated 2 million times per day. It hosts all real time transaction. There are 200K records in this table. Would you please to share your experience with me about how to protect/save such table in SQL 2000 from any possible damage?
We plan to use point-in-time backup (every 5 minutes). It still takes at half an hour to recover the whole database. Any new technology from Microsoft or SQL 2000 you can recommend?
Can any one recommend an approach for identifying the frequently accessed tables and files in a SQL/Server application? Particularly, if the database is stored on raw partitions instead of FAT or NTFS. Thanks.
I have Oracle 9i. Oracle listener is aborting by itself after every few minutes giving TNSLSNR.exe failed. While listener is running I can do all the activity on the database.
I use SQL2005 EE to capture the "In Progress Data" from the Devices and have connected it to the Main server-SQL2005 SE thro linked Server. I Run a Job that updates the Main server and Clears the "in Process Data". Off late I have been seeing that the systems with SQL2005 EE have gone slow ? I have not investigated the reason. But wanted to find out if using this method ,should I need to take additional precautions ?
If you have followed a link to this page (i.e. the URL contains "SearchTerms=xxx") please scroll down to see items of interested highlighted
This list of SQL Server Frequently Asked Questions (FAQ) was originally compiled in August 2005 based on the most frequently "read" posts on SQL Team. Since then new links have been added as topics become popular - so it might be better referred to as FGA - Frequently Given Answers!
NC=Indicates that the Article has NOT been checked for relevance. As time goes on these are getting fewer and fewer The latest change is in Red Recent changes are in Teal
URL to link to this post: 17Nov2005 http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms= Followed by either "Keyword1,Keyword2" or "PhraseWord1+PhraseWord2"
The icon allows you to RightClick-CopyShortcut to provide a link to this topic with appropriate keywords - I got bored of having to make them manually! 07Mar2006 Stats
Homework I put this one at the top, in case you don't read any further. To find out if your homework will be answered on this forum you should see if it qualifies: Requirements for homework questions 07Mar2006 Example of Failure to meet the minimum requirements 07Mar2006 Learning SQL www.sql-tutorial.net 07May2007 www.firstsql.com/tutor.htm 07May2007 www.w3schools.com/sql/default.asp 07May2007
Why? Why is my LDF Log File so big / getting bigger / bigger than my MDF 14Oct2005
How to
How to ask a question on SQL Team and get a quick answer - i.e. the information you need to provide 06Nov2006 How to format your question or a reply (in particular see the [code] option 18Sep2007 how to encrypt and decrypt my password 07May2007 Rounding up/down to nearest multiple (e.g. order in dozens, buy at least 30) 28Sep2006 Replace multiple spaces, or other character, with single space 28Sep2006 Generate a Random String 13Sep2006 String comparison 24Jul2006 Article: Images and SQL Server How to get Images or blobs into SQL table (NC) Inserting Images as BLOB in SQL server table (NC) How to use DeBUG window in QUERY Analyzer (NC) Use a Parameter in the Top clause Dynamic SQL or How do I SELECT TOP @var records? Can't insert NULL into table with unique key (NC) Efficient paging of recordsets with T-SQL Article: Paging in SQL 2005 07May2007 Execute dynamic SQL that is longer than varchar(8000) 05Oct2005 Convert multiple spaces to single spaces 14Oct2005 Making Upper/Lower Case Sensitive comparison 27Oct2005 Convert to Proper Case (each word starts with capital) 19Feb2006 Deleting a massive number of rows 04Mar2006 Combine values from rows into a column 05Oct2005 i.e. FOO 1 FOO 2 becomes: FOO 1,2
CSV / Splitting delimited lists WHERE IN @MyCSV Article: Passing a CSV or Array to a Stored Procedure (NC) Best split functions and Concatenating data from rows with same GroupBy column Triggers Triggers to audit changes trigger to keep tables matching Set Update/Modified date column using a trigger 02Nov2005 Deactivating a trigger 07Feb2006
SQL Team Articles Article: Identity and Primary Keys - and Surogate Keys See also Article: Sending SMTP Mail using a Stored Procedure (NC) Article: Dynamic ORDER BY (NC) Article: More Trees & Hierarchies in SQL (NC) Article: Using SELECT to INSERT records (NC) Article: Deleting Duplicate Records Article: Returning a Row Number in a Query (NC) Article: Calculating Running Totals (NC)
Datatypes / Collation
GUIDs (NC) IsGUID check GUID is valid 01Aug2007 DATALENGTH() and LEN() 21Sep2005 Compare BIT columns and a BitMask column 05Jan2006 Collation conflict in Assignment or WHERE clause 05Feb2006 (See "Developer / Techie stuff" below for some other Collation links)
Datatypes - Dates
Time Only Function: F_TIME_FROM_DATETIME 29Apr2006 Date/Time Info and Script Links (including UNIX time) 16Apr2006 Date formatting ( Format Date/Time (NC) last date of the month (NC) Getting the date portion of a datetime value or Round a date to Year, Quarter, Month, Day, Hour or Minute How to get date in t-sql (NC) compare date with current date (NC) convert varchar to datetime (NC) Compare dates regardless of time? (NC) Convert varchar to date (NC) Time in Analog (NC) Start of Week Function (NC) Earlier date than 1/1/1753
Techniques
Prevent Administrators accessing a database 14Sep2006 SELECT vs SET 26Sep2005 What is a cursor, Why is it bad? 23Sep2006 Cursor or Not (NC) TSQL/ SP Best Practices (NC) case-sensitive (NC) User-Defined string Functions Transact-SQL (NC) Passing an array into a stored procedure (NC) Comparing two tables or views easily (NC) All Tables in All Databases (NC) Better Phonetic Matching Algorithm (A better Soundex) Levenshtein Edit Distance Algorithm (A better Soundex) Fuzzy matching 01Aug2007 Find tables with no PK (NC) Function: HTMLDecode (NC) How to protect errorlogs to tables from rollbacks (NC) Distance of Zip/Postcodes Great Circle Formula 07May2007 Haversine Formula 07May2007 Accuracy v. Speed 07May2007 See also here, here, here, here and here and here Upsert - combined Update/Insert Procedure 01Aug2007 and here Display all columns but only for rows with the most recent date 01Aug2007
Developer / Techie stuff
Changing column names on referencing objects 07May2007 When was DB object last updated 07May2007 How to clear the whole database 07May2007 Move / Script Development Database Changes to Production Database / Ship Application updates 04Nov2006 Script to analyze table space usage 11Oct2006 What version, and Service Pack, of SQL Server am I using? 23May2006 SQL Beautifier 13Apr2006 Performance / System Monitor / PerfMon - preferred values for counters 04Apr2006 SQL Server 2000 Knowledge Base Articles - updated every 3 days 21Jan2006 Concerns about SQL 2000 SP4 08Jan2006 Support stops for SP3a AND installing sp4 on cluster 26May2006
How to read Mssql transaction log file Compare data in two tables / two databases 31Oct2005 Recommended books 07Oct2005 Good tools for DBAs 06Oct2005 Best SQL Security Method (NC) Some query optimalisation (NC) Requirements for Horizontal Partitions Multiple SQL Server 2000 Instances (NC) Primary Key v. Unique Index (NC) HOWTO Run SQL Profiler without sysadmin rights (NC) upgrade from SQL7 to SQL2000 (NC) xp_cmdshell execute right (NC) Monitor object usage over time (NC) size of user tables in a database (NC) Changing Column Length (NC) Add, Sub, Mul, Div With Really! Big Numbers (NC) So you're a DBA eh?! Why I'm not a DBA (NC) Do you S-Q-L or Sequel (NC) Interview questions (NC) More Interview questions 11Sep2006 Best steps to becoming a DBA (NC)
Developer / Techie stuff - Collation
Bulk Delete of Records 07May2007 and locking issues 01Aug2007 Deleting lots of Records from a large table 01Aug2007 Synchronising data using staging tables 07May2007 Version Control 07May2007 how to change Collate on the server 20Sep2005 How to change default collate in SQL 20Sep2005 Cannot resolve collation conflict for equal to OP 20Sep2005 different Collation Settings between Databases 20Sep2005
Database Design and Structures
Codes - Common Lookup Tables CLT 04Jun2006 Good table naming convention 09May2006 Naming Store Procedures 09May2006 Recursion / Hierarchy 29Apr2006 Hierarchies (NC) Normalisation (NC) NULL opinion? (NC) Finding evidence of sql injection attack Security Testing: SQL Injection 09May2006
Locking
Using the NOLOCK hint 07Jun2006 how does row locking work (NC)
EMail
sp sending mail (NC) CDOSYS Send Email (NC)
XML
SQL Server 2000 XML (NC) Adding an XML Root Tag Handling tricky namespaces in OpenXML
Backup / Restore / Replication / Jobs / Houskeeping
Backup How Backup works What type of backup should I use? - Full, Differential, Transaction? Should I shrink the log? 22Jan2006 Automating Backups - Scripting v. Maintenance Plan / Wizard 08Mar2006 Backup to Disk, or direct to Tape? 05Dec2006
Disaster Procedure Checklist I think I have a database corruption, how do I mitigate any further damage and get upright again? 07May2007 How I Rescue Data from Corrupted Databases 07May2007 Disaster Recovery Plan 07May2007 Quiesce the SQL Service to enable low-level copy 01Aug2007
Restore RESTORE syntax / example Restore SQL 2005 to SQL 2000 via Downgrade 07May2007 Restore Full and all TLogs backups based on files in disk folder 07Dec2006 Move database to a new server (with minimal downtime) 16Feb2006 Moving to a new sql server 25Jun2006 Fix Orphaned Users (after a Restore or moving DB to a different server) Script User Logins after a Restore 01Aug2007 and Scripting users & logins from one server to another (e.g. after moving DB to a different server) 25Jul2006 how long will take to restore a 10 gb? All I have is the .bak file Restoring .BAK file to a different server? Unable to restore/attach a MDF file (single file attach / sp_attach_single_file_db) See also: This and this and this
Shrink Database / Files
Shrinking TEMPDB 19Apr2006 Database Shrinking 09Jan2006 Log Shipping -Shrinking Log and Data files (NC) MSDB Massive msdbdata.mdf
Housekeeping / Maintenance
Tara Blog Houskeeping Routines 06Oct2006 Index Tuning Wizard 07May2007 User Rights for SQL Service 07May2007 When was SQL Server last restarted? 07May2007 Optimising your indexes with DBCC INDEXDEFRAG 06Oct2006 Detach Move Db & Log File Reattach 17Mar2006 Rebuilding Indexes DBCC CHECDB, CHECKTABLE, NEWALLOC (old) Suspect Databases after Power Cut? Jobs failing (NC) Reindex All Tables in All Databases (old) deleting replication (NC)
Export / Import / DTS
Copying/backing up DTS Packages (NC) Export to Excel (NC) Generate INSERT statements for N rows of data Tool to script database records? (i.e. generate INSERT statement script) How to convert DATE Format from DD/MM/YY to MM/DD/YY in DTS (NC) Importing an Excel File with DTS (NC) Is DTS Secure for credit card backup to Access? (NC) Winzip in scheduled DTS Package (NC) Article: Using BULK INSERT to Load a Text File (NC)
Output / Reporting / Formatting
Pivot table (NC) Article: Dynamic Cross-Tabs/Pivot Tables (NC) which led to: More Dynamic CrossTabs using T-SQL 04Aug2006 (Jeffs Blog)
Error Messages
SQL Server does not exist or access denied (NC)
Connections
Linked Server Newbie Question (NC)
Configuration / Hardware
/3GB in boot.ini on Win2003 standard 19Oct2005 SQL memory /3gb /PAE AWE 19Sep2005 SQL Server Standard & 4GB memory Using AWE option in SQL Increasing SQL Server Memory
MSDE
MSDE Setup fails (NC) MSDE Install Issue (NC) Installing MSDE on XP Pro (NC) Backing up MSDE database (NC)
SQL 2005 / Yukon
Migrating to SQL 2005 Hints and Tips 01Aug2007 SELECT not allowed in Yukon/SQL2005? (NC) Download Yukon/SQL2005 (NC) SQL Server Management Studio (NC)
MySQL, Oracle, and the others
MySQL not as good as MS SQL? Migrating from Oracle to SQL Server
Other
SQL Reporting Service SP2? (NC)
Got an hour .. or ten ... to spare?
Would you work at Elwoo's office? Simple Quiz What is a Yak? 07May2007
Hey guys. I need a little help once again, here's the problem:
We are using an attendance system software that adds records in an Access 97 table whenever someone logs in or out of the room (Yes, it's old and I hate it, but it came with the hardware).
So we plan to create a program that lets admins check those login/logout data in an SQL Server 2005 database using a Visual Basic as the frontend.
Our only problem is, how do we transfer data from the Access 97 tables to our SQL tables *everytime* it gets updated? We don't need every detail the Access97 table has (it has IDNo, CardNo, Time, Location, plus other useless stuff). We just need to extract the IDNo(int) and Location(varchar) field(we'll just use getdate() for the Time since the update is done in realtime anyway).
So in a way, we are trying to find out a way to technically sync both tables, just like Database Mirroring style.
We are receiving following alerts frequently about 1:40 AM in the morning. We have backups running on 11:00 PM everyday and rebuild job running at 2:00 AM. Not sure the exact cause of this error.
Error: The file group "PRIMARY" for the database "tempdb" in SQL instance "MSSQLSERVER" on computer "XYZ" is running out of space. tempdev Initial size : 133,100 MB Growth: By 10 percent, Limited to 140000 MB templog  Initial Size : 5,475 MB   Growth: By 10 percent, Unlimited