I am working on SQL Server 2005. I have took the backup and restore the database. I just wanted to know is there any way I can check whether the data between these two database are diffent. or any script that I can run or check [ could be table by table] to see if any new row added or modified.
EDITED
For example - I have to check the data difference from Database 1 Table_User to Database 2 Table_User.
Thanks
You can use the built-in command line tool TableDiff.exe:
http://msdn.microsoft.com/en-us/library/ms162843(SQL.90).aspx
It performs row by row comparisons along with column-level comparisons. Here's an article that walks through how to use it:
http://www.databasejournal.com/features/mssql/article.php/3594926/SQL-Server-2005-TableDiff-Utility.htm
And another (with a link to a GUI that you can download):
http://weblogs.sqlteam.com/mladenp/archive/2007/03/03/60125.aspx
This would be on a table by table basis - but it's free and already installed for you since you have SQL Server 2005 installed. Hope this helps!
you can use sql compare and sql data compare.(red-gate.com)
or you can use sql delta.(sqldelta.com)
I think you want to track what are changes in your restored database comparing to that before it was restored. If so, I hope this may be helpful.
ALTER DATABASE yourdatabasename SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON);
GO
USE yourdatabasename;
GO
ALTER TABLE Person.Person ENABLE CHANGE_TRACKING
WITH (TRACK_COLUMNS_UPDATED = ON);
GO
Related
I have a SQL Compact 4.0 installed on my System and I am using it with VS2012. On VS2012, i have SQL Server Compact/SQLite toolbox extension installed.
This extension gives various options i don't find any truncate table option. Query truncate table tblTransaction doesn't seem to be working. I tried delete query but it doesn't reset the start point. I have a option to Drop and Recreate the table using extension to delete content as well as reset the Identity Column start.
My question is :
Is there any way to truncate SQL Server Compact database. I have about
65 tables in database and i need to truncate the whole database. Not just delete the data but to reset the start point of Auto Increment column.
You can reseed the IDENTITY value by running this statement:
ALTER TABLE [MyTableName] ALTER COLUMN [Id] IDENTITY (1, 1)
In addition I have created this feature proposal, feel free to vote (or even contribute) https://sqlcetoolbox.codeplex.com/workitem/12109
Using MS SQL Server Management Studio 2008.
I have a db (say ip 10.16.17.10 and called db1) and a second one (say ip 10.16.17.25 called db2).
I am trying to copy one table (and its contents) from db1 into db2.
I have the database on both (but empty in db2).
The problem is no matter how I copy/export/import, no matter what options I set in MS SQL Server Management Studio 2008 when I click 'table'->'Design' (on db2) it ALWAYS says 'Identity Spefication: NO' even tho the db1 table has it on.
From db1 I go to 'Tasks'->'export'->'source/db' and 'destination/db'->'Edit Mapping'->'Enable identity Insert' and click it on.
But no joy. ALWAYS exports without it.
I try similar thing from IMPORT on db2. Similar thing if I use COPY.
I have read MANY of the STACKOVERFLOW articles on this, they all suggest setting IDENTITY_INSERT setting to ON but when I do run below:
SET IDENTITY_INSERT [dbo].[mytable] ON
The table either doesn't exist yet or has already copied WITHOUT the identity setting on so see the error:
does not have the identity property. Cannot perform SET operation.
I have tried setting it as a property (under database properties) for db2 but when I copy/import/export never works.
Would appreciate any help here as lots of StackOverflow articles so far all seem to be having an easier time than me.
I am planning on doing this for another 50 or so tables in this database so am hoping to find a way which doesnt involve running scripts for each table.
thanks
The process of using the Export Data Wizard to copy the data from one table to another will NOT replicate all aspects of the schema (like identity and auto-increment). If you want to replicate the schema, script out your table into a create statement, change the name to db2, and create it. Then you should be able to run the export/import wizard with the identity insert option on and insert into your new table that replicates the schema of your old table.
Ended up sorting this out using MS SQL Management Studio.
Thanks to #kevin for the help regarding Import Data and Export Data. Schemas are NOT transferred across however they are the best means to transport the data once schema is up.
Found best way to MASS import/export db table schemas using below (Saved SQL create scripts to file):
Tasks->Generate Scripts->All Tables To File->with Identity on
Ran 200kb SQL file on db2 for schema.
Then ran Import Data from db1 to db2.
Done, all Identity_Inserts maintained.
thanks for help
According to the Error message I think your table does not have an IDENTITY column. Make sure that [dbo].[mytable] does have an IDENTITY column before you executing SET IDENTITY_INSERT.
SET IDENTITY_INSERT [dbo].[mytable] ON
DEMO1 (Trying to set identity ON when there is NO identity column)
--Error
'Table 'T' does not have the identity property. Cannot perform SET operation.: SET IDENTITY_INSERT T ON'
DEMO2 (Trying to set identity ON when there is identity column)
--No Errors
Follow following Steps :
From db1 I go to 'Tasks'->'export'->'source/db' and 'destination/db'->'Edit Mapping'->'Enable identity Insert' and Edit SQL - > You will able to see query structure of Table.
IN the query for eg. ID int NOT NULL, do the next step ID int NOT NULL IDENTITY(1,1)
Then proceed.
I bet it will work.
I know you can go into the design view of a table in SQL Server Management Studios and reorder columns as they appear in the design view, however this isn't possible with SQL Azure as the option is disabled. Is there a way to modify SQL Azure tables so that you can reorder their columns as they appear in the design view?
I have been running a number of database upgrades over the last few months to support new requirements and would like to reorder the way the columns appear in design view so they're easier to read, i.e. so they start with a primary key, followed by foreign keys, then normal columns and end with the added by, modified by fields. Its purely to make the tables more readable as I manage them over time.
Just run a script against the table. Its a bit of pseudocode but you should get the idea.
CREATE TABLE TableWithDesiredOrder(PK,FK1,FK2,COL1,COL2)
INSERT INTO TableWithDesiredOrder(PK,FK1,FK2,COL1,COL2....)
SELECT PK,FK1,FK2,COL1,COL2.... FROM OriginalTable
DROP TABLE OriginalTable
Finally Rename the table
sp_Rename TableWithDesiredOrder, OriginalTable
Just another option: I use SQL Delta to propagate my db changes from dev db up to Azure db. So in this case, I just change the col order locally using SSMS GUI, and SQL Delta will do the createnew>copytonew>dropold for me, along with my other local changes. (In Project Options, I set Preserve Column Order=Yes.)
I experienced the same with Azure SQL Database, basically my view changes with ALTER were not taken when did a SELECT * from the view, or the column headers were mixed with the column values.
In order to fix it I dropped the view and re-created it again. That worked.
I have FK and PK all over my db and table data needs to be specified in a certain order or else I get FK/PK insertion errors. I'm tired of executing the wizard again and again to transfer data one table at a time.
In the SQL Server export data wizard there is an option to "Write a query to specify the data to transfer". I'd like to write the query myself and specify the correct order.
Will this solve my problem?
How do I do this? Can you provide a sample query (or link to one)
The databases are on two different servers - SQL Server 2008 on each ; The database names & permissions are the same ; each table name & col is the same ; I need Identity Insert for each table.
Disable foreign keys before importing, enable them after the import:
ALTER TABLE tablename NOCHECK CONSTRAINT ALL
ALTER TABLE tablename WITH CHECK CHECK CONSTRAINT ALL
Update: Thanks for the comments, I fixed the syntax.
You could always save the package and then open and edit the package to put things in the right order (you might have to copy the data flow several times and put dependencies between them)
You can use 3rd party tools to transfer a data; these tools disable/enable constraints automatically.
I am busy creating tables in Sql Server from a Sybase database. In the Sybase database when the tables are created an option 'lock allpages' was used, how can I replicate this when creating the tables in Sql Server 2005.
In SQL Server you cannot specify a lock option for the table in CREATE TABLE. You can at most disable row level and page level locking by adding the WITH ALLOW_ROW_LOCKS = OFF or WITH ALLOW_PAGE_LOCKS_OFF. The equivalent of locking the entire table in SQL Server is to use a lock hint WITH (TABLOCK) when running queries and updates on the table, but that is not recommended.
My recommendation would be to just ignore this option when transferring the tables from Sybase to SQL Server.
What do you want to achieve with this "lock allpages" option? Is the database you're working on up and running productively? If not, in SQL Server, you can restrict access to the entire database to a single user:
ALTER DATABASE YourDatabaseName SET SINGLE_USER
and that way you're sure no one else if going to come in your way and fiddle around until you're totally done :-)
Set it back to "normal" usage with:
ALTER DATABASE YourDatabaseName SET MULTI_USER
Marc