Recover Updated Data - SQL Server 2005 [closed] - sql

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have an issue that, while using sql server 2005 i have executed update query without where clause (by mistake) and all the original values of the column get lost.
How can I get old values??
Any suggestion/tips/solution is welcome and will be highly appreciated.

Hi AngelIII,
SQL server keeps log for every transation.So you can recover your modified data from the log as well without backup.
Select [PAGE ID],[Slot ID],[AllocUnitId],[Transaction ID] ,[RowLog Contents 0]
, [RowLog Contents 1],[RowLog Contents 3],[RowLog Contents 4] ,[Log Record]
FROM sys.fn_dblog(NULL, NULL)
WHERE AllocUnitId IN
(Select [Allocation_unit_id] from sys.allocation_units allocunits
INNER JOIN sys.partitions partitions ON (allocunits.type IN (1, 3)
AND partitions.hobt_id = allocunits.container_id)
OR (allocunits.type = 2 AND partitions.partition_id = allocunits.container_id)
Where object_id=object_ID('' + 'dbo.student' + ''))
AND Operation in ('LOP_MODIFY_ROW','LOP_MODIFY_COLUMNS')
And [Context] IN ('LCX_HEAP','LCX_CLUSTERED')
Here is the artcile, that explains step by step, how to do it. http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/

Restore a backup taken before the update
Restore transaction logs to a point in time before the update
Restore a copy of the table you made before the update
Rollback the transaction that contains the update
It's difficult to offer a specific solution not knowing what precautions you have taken. These may not solve your problem, but may prevent this from happening in the future.
DON'T MESS AROUND WITH SQL THAT ALTERS PRODUCTION DATA UNTIL YOU HAVE ANSWERED THIS QUESTION.

Related

SQL Insert Query With Condition Exception [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I have this query:
String requete = "INSERT INTO reduction(newPrix) VALUES (?) "
+ "WHERE id_prom=? AND id_prod=?";
I am getting an exception:
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'WHERE id_prom=2 AND id_prod=6' at line 1
I'm wondering why the INSERT query was failing. Any advise appreciated.
You insert a row into your table.
This means that you need to specify all mandatory values (i.e. values for the columns that are not nullable and don't have a default value).
You can't use a where clause in this kind of insert statement. What would it mean? And in your program you can verify the validity of the data you'd like to add to your table and decide to insert or not.

What is a clean way to copy a SQL table with more than 1000 rows? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I know the question "How to copy table with more than 1000 rows" is already asked. I have read a lot about it and the different solutions like:
use export to excel and than import in new table
use UNION ALL (but not recommend)
use bulkreader
export to file and import
etc.
All the solutions sounding like a workaround. I am asking myself, is there no "official", clean way to do it?
Thank you.
Edit:
SELECT INTO was tried
INSERT INTO was tried
Using sql MS MGM studio
using HeidiSQL
Working on a MS SQL Server 13.0.4001.0
The cleanest and fastest solution with T-SQL would be into:
select *
into [destination table]
from [source table]
This will copy your data into a [destination table]. Be mindful of the remarks and limitations in the documentation regarding this keyword.

Why some rows can be inserted into and some cannot? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
When I use the Cashier table or some other tables that have small amounts of records the process proceeds and table is inserted into the external database. But when I change the cashier into the transaction database (400k+ records), Visual Studio reports an error near "Transaction" Help would be appreciated thanks.
Cashier Database (working)
Dim query As String = "select * into MyDatabase2.dbo.Cashier from bos_primary_db.dbo.Cashier"
Transaction Database (not working)
Dim query As String = "select * into MyDatabase2.dbo.Transaction from bos_primary_db.dbo.Transaction"
This is the error message:
Incorrect syntax near the keyword 'Transaction'
this is probably because Transaction is a reserved word in SQL.
Depending on your RDBMS (that you didn't specify), there are ways to "escape" it:
for Sql Server, you should wrap reserved words in square brackets:
select * into MyDatabase2.dbo.[Transaction] from bos_primary_db.dbo.[Transaction]
For MySql you should use an apostrophe:
select * into MyDatabase2.dbo.`Transaction` from bos_primary_db.dbo.`Transaction`
For Oracle you should use double quotes:
select * into MyDatabase2.dbo."Transaction" from bos_primary_db.dbo."Transaction"
Note: You should always try to avoid using reserved words. This link describes my favorite way of do it.

Error message from simple SELECT statement with practice database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I use the AdventureWorks practice database attached to SQL Server 2012.
A simple statement like:
SELECT * FROM HumanResources.Shift;
gives me this error:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'AdventureWorks2012'.
I also tried:
USE master
GO
SELECT * FROM HumanResources.Shift;
Received same error message. Any idea to why this is happening?
Is AdventureWorks2012 the name of a database or a table?
USE <database name>
means use the specified database to run the query against.
SELECT * FROM <table name>
means select all the rows from the specified table.
--Edit because of change in question--
You don't want to use Master, you want to use the name of your DB. Next, using the object explorer, I would make sure the table actually exists in the Database you created.

display information from sql server view [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
New to views with sql server, not sure how to view the information it has gathered with vbscript. I know it is not as simple as:
select * from EXAMPLE_VIEW
I want to get the information from my example view loop through it and display it, however when i try to do that sql query i get invalid object name.
My question is how do you sql query a view
You should probably be doing this:
SELECT column1, column2 FROM dbo.EXAMPLE_VIEW;
This is because if your user has a different default schema than dbo, it might be checking for some other view with the same name under a different schema. (You also know not to use SELECT *, right?)
So you should also make sure your user account has select permissions on the view and/or the table(s) behind it.
Bad habits to kick : using SELECT * / omitting the column list
Bad habits to kick : avoiding the schema prefix
select * from EXAMPLE_VIEW
...is the correct way to query a SQL Server view.
If it's not working for you, you have a different kind of problem: maybe no permissions, maybe no server connection, maybe a view called EXAMPLE_VIEW doesn't exist, maybe something else.
Whatever it is - we need the exact error message and as much example code as possible to help you.
But the SQL itself is correct.
Is your current database set correctly after establishing connection? It can be set using connnection string (http://www.connectionstrings.com/) or by specyfying it witin query itself:
SELECT * FROM MYDB.dbo.EXAMPLE_VIEW;