c# ssdt row edit & using where - azure-sql-database

I want to edit the data in a rather large mssql table that is in a Windows Azure SQL Database. So, I try this by creating a query with a "where" clause, and then I expect to edit some cells by choosing them directly from the results pane.
I try to use Microsoft SQL Server Data Tools (last, 11.1.30618.1), VS 12.
I found two modes:
http://i.stack.imgur.com/1UsOf.png — i can't edit cell's
http://i.stack.imgur.com/Fh1lc.png — i can't found my query to add where section
I ve tried another solution:
http://darrylbajaro.wordpress.com/2011/09/25/how-to-edit-ms-sql-records-with-filtering-on-sql-management-studio/
But since I'm using a Windows Azure SQL Database, it does not have the same options and so will not work (ssms 11.0.2100.60): http://i.stack.imgur.com/X0J7x.png
I d like something like heidli sql (I've used it many years for mysql), but for azure+mssql, maybe someone knows?

Related

Comparing similar tables in different SQL Server databases

While Googling for a way to compare two tables (same schema) that are located in two different databases, I came across the tablediff.exe utility which works great for creating a script to make changes in table B so that it matches table A.
However, in my case I need changes to be made to table B only if the data in B is older than that of A. Otherwise, the change needs to be applied to table A.
Is there a way to do it using tablediff.exe, and if not is there any free command line alternative?
The Community (free) version of Visual Studio has 'Data Comparison...' for SQL projects. Right click on the object in SQL Server Object Explorer and specify Source and Target...
Here are some screen shots
Right click (in VS (Dark Mode) SQL Server project) in the SQL Server Object Explorer on the Table to compare.
Connect to the 2 instances
Then select the object(s) and voila!
I cannot comment on the conversation from above, but to add to SteveC comments, Visual Studio does have a Data Compare utility.
Tools > SQL Server > New Data Comparison

Excel query showing different result than SSMS query

I have had an odd error I cannot explain. Basically, I am running a query to my SQL database using excel and am having non-existent data pop up when it comes to a very particular order in my database.
Here is a simple query surrounding this order:
select * from OR200100 where OR200100.OR20001='0000793605'
Here is the output in EXCEL
And here is the same output in SQL
what is happening here? How could the same query generate 2 different results?
Run SQL Server Profiler against the database if you can, then compare the output to the sql query that you are running in ssms.
OK, so it's SQL Server then, that's important because different SQL products can have very different idiosyncrasies and controls.
The next things to check are these:
Is OR200100 a Table or a View? If it's a view then post it's code.
Are you using the same Login/account from both Excel and SSMS?
Are you sure that you are connecting to the same Server and Database? SSMS tells you what you are connected to, but client apps like Excel do not and it is very common for this type of problem to be caused by the app connecting to a Dev or QA version of the database. See here for some of the different ways that this can happen:
So I had a very similar problem, my query was grouping by week numbers. What I found was that one of the queries had set datefirst 5 set whilst the other didn't. I guess the key thing here is make sure, if you are using any SET operations in your ssms queries, these are identical to those in the Excel query string.

Why SQL Server 2008 Management Studio doesn't have option "Open table"

I used to have option to open table in SQL Server 2005 Management Studio, but don't have that anymore in the 2008 version. Does anybody know why this option has been removed? And, if this feature is no longer available in the 2008 version, what is the best alternative to use?
Now it's Edit Top 200 rows.
They did this cause people were opening huge tables without thinking.
If you want to see 2000 rows, you can edit the select query when you right click -> pane -> SQL.
Then in your sql statement you will see Top(200). you just have to change to the number of rows you need.
The option is still there, it's just been renamed. I believe the old version used to attempt to get every single record in the table. The revised SSMS will, by default, get only the first 200.
Right-click a table and select Edit Top 200 Rows as shown below:
its good to change it like-
tools-> options ->SQL server object explorer -> commands --in this we can edit for whichever rows..

Microsoft SQL Server: How to export data from a database and import them to another database?

How can I export all of my rows in a table to sql script in Microsoft SQL Server 2005 and then import them to another database?
Thanks in advance
If you moving it to another sql db you can right click the database you want and choose tasks -> generate scripts. That will launch a a wizard - follow along, choose the option to script all tables and data. Then execute that script in the new db(assuming that you've already created one with the same name)
If you can't find a data import/export tool that will work in your particular circumstances, it's possible to write plain SQL SELECT queries that will generate SQL INSERT statements. In this way it's possible to "export" all your data to a script file that can be run against the destination database. It's kind of an ugly hack, but it's simple and it works if you don't have a lot of data to move. See my answer to this question for details: Export SQL Server 2005 query result to SQL INSERT statement?
Note that this method assumes that the destination table already exists. But it's pretty straightforward to generate table creation scripts, as J Cory's answer has already shown.
There's a command line tool available to dump your data from particular tables into a SQL script that be executed against a different database:
http://blog.sqlauthority.com/2007/11/16/sql-server-2005-generate-script-with-data-from-database-database-publishing-wizard/
I don't believe SQL Management Studio Express supports data scripting (as your screenshot on J Cory's answer shows), but the full version does support that feature. In either case, the command line tool should accomplish what you need.

How to do a search and replace of a part of a string in all columns in all tables in an sql database

Is it possible to search and replace all occurrences of a string in all columns in all tables of a database? I use Microsoft SQL Server.
Not easily, though I can thing of two ways to do it:
Write a series of stored procedures that identify all varchar and text columns of all tables, and generate individual update statements for each column of each table of the form "UPDATE foo SET BAR = REPLACE(BAR,'foobar','quux')". This will probably involve a lot of queries against the system tables, with a lot of experimentation -- Microsoft doesn't go out of its way to document this stuff.
Export the entire database to a single text file, do a search/replace on that, and then re-import the entire database. Given that you're using MS SQL Server, this is actually the easier approach. Microsoft created the Microsoft SQL Server Database Publishing Wizard for other reasons, but it makes a fine tool for exporting all of the tables of a SQL Server database as a text file containing pure SQL DDL and DML. Run the tool to export all of the tables for a database, edit the resulting file as you need, and then feed the file back to sqlcmd to recreate the database.
Given a choice, I'd use the second method, as long as the DPW works with your version of SQL Server. The last time I used the tool, it met my needs (MS SQL Server 2000 / 2005) but it had some quirks when working with database Roles.
In MySQL, you can do it very easily like this:
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
I have personally tested this successfully on a production server.
Example:
update users set vct_filesneeded = replace(vct_filesneeded,'.avi','.ai');
Ref: http://www.mediacollege.com/computer/database/mysql/find-replace.html
A good starting point for writing such a query is the "Search all columns in all the tables in a database for a specific value" stored procedure. The full code is at the link (not trivial, but copy/paste it and use it, it just works).
From there on it's relatively trivial to amend the code to do a replace of the found values.