Is it possible to edit a sql query using a query itself - sql-server

I have a sample query to insert data into the table.However, a table name has been misspelled. The same mistake is continued for about 120 records. Is there any query that can be written so that I can correct it in one record and apply the changes to the rest automatically? or do I have to do it manually?

Yes, it possible in SSDT Project.
create SSDT Project
import your database
right click column in script and choose Refactor->Rename

Related

Importing data from Excel to SQL table using button

I have an Excel file that looks like the below
System | Status
Test OK
Test2 Down
Test3 OK
I also have a SQL server table with the same columns.
What I want is a button on the Excel sheet that once clicked, will truncate the SQL table and insert the values from the Excel table into the SQL table.
I have tried the below step but I am struggling due to my lack of understanding of developing in Excel (I am a SQL developer)
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/84725bcb-328d-4aed-8b95-d2c34dc46be4/need-to-update-sql-server-table-on-click-of-excel-button?forum=sqldataaccess
Any help would be massively appreciated!
Thanks
We have created an Excel Add-In for updating tables from Excel to SQL Server which have a Save button that will save your changes in Excel to the mapped table in SQL Server. The Add-In is built for non-technical people so it is rather straightforward to set up the spreadsheet without having to write any code.
It won't truncate the table, but there are a couple of ways to update the table which hopefully will give you the same result. Without knowing your exact use case, I would propose to either just do an update of the table from Excel if that meets your requirements, or add a timestamp column and let the Add-In write the timestamp to each updated/inserted row and then only use the last updated/inserted rows (you can also let the Add-In delete all previous rows after a new insert).
If that's of interest, you can read more here and download a free trial.
Disclaimer: I'm the founder of the company.

In SqlSvr 2008R2, how would a search a Table for a record, then edit THAT record

In my SQL Server 2008r2 database I have a Table with over 25000 records in it. when I search for the record i need to edit, it returned 6 possible, but it wont let me edit. I can just open the table and go through all 25000 records, which is painful. I would like to be able to search for the right records, then be able to edit those records.
The best option is to write an UPDATE. I could give you an example on how to do it, but since you didn't post any code, I can only give you the examples on the documentation.
Review the documentation on UPDATE.
If you're using SSMS, this may be helpful: How to quickly edit values in table in SQL Server Management Studio?
If you aren't using SSMS, knowing what UI you're using would be helpful.

SQL Server : best way to check values before insert to table

I am working in a company that has software that can connect to a database and push values to a table.
I have a problem that some properties do not insert into the database.
I check regular insert query in the SQL Server Management Studio, and the insert is ok there.
I want to check the values that came from my software company before insert to the table.
Friends, please help me.
Thanks
You can use extended events(light weight version of profiler).You may choose filters as per your requirement and in set session filters screen you can try scoping to a single database or a table or even some text using like syntax
Below are the steps

Right click to query temporal tables not working

I have SQL Server Management Studio 2016 loaded with Microsoft's test database (WideWorldImporters) but for some reason, any table that is a temporal table does not give me the option of right clicking and selecting the last 1000 rows as all other non-temporal tables allow.
Am I missing something which needs to be installed or is there an alternative way of querying the table for data?
Right Clicking does not work. But in the session that created the table you can do any kind of query that can be done against any other table.

Visual Studio DataSet Designer Refresh Tables

In visual studio datasource designer is there any way to refresh a table and its relations/foreign key constraints while keeping the custom queries?
The way I am doing it at the moment is removing the table and adding it again. This adds all the relations and refreshes all fields.
Also if I change a fields data type, is there a way to automatically refresh all the fields in the datasource? Again without deleting the table and adding it again.
Reason for this is because some of my TableAdapters have quite a number of complex queries attached to them and when I remove the table the adapter gets removed as well including all its queries.
I am using Visual Studio 2008 and connecting to a MySQL database.
Any1 have an idea?
Each table has a default query (The one on top with the check on it). When you dragged your tables in to the dataset to create the query, it wrote a SQL statement which it uses to schema your table. Keep that query simple, you might not actually use it in code, and you can always edit that query to update the table schema.
Every time you open the default query it connects to your datasource and allows you to select new columns that weren't in there before. If you want to update your existing columns, delete all the columns out of the table before you attempt to open the query. When you save the query, your updated columns get added back.
Make sure your connection string has permissions to view column information.
I reported this to MSFT but no response. The designer hangs all the time on the simplest of SQL statements. What I found that works for me is.
Add a new table to the designer.
Save it.
Shut down visual studio 2010.
Start VS 2010.
Add one or two more SQL statements and follow steps 2-4 again.
This is a pain in the neck but the only thing that stops Visual Studio dataset designer from hanging. I experienced in this same issue in VS 2008. I am connecting to Oracle but still shutting down VS and starting it back up works, but really, this is nonsense.
You can add/change/remove fields and relation ships, but i would suggest looking into NHibernate.
You should be able to right-click the dataset in solution explorer and select "Run Custom Tool" to refresh the table and it's query/relationships.
If that command is not there, check that the dataset properties has "MSDataSetGenerator" in the Custom Tool field.
Right click on your DataSet name and select Dataset Properties
Below the Query box you will see a button for Refresh Fields.
Click on Query Designer and the new field should show in your table list.

Resources