Updating a table in SQL Server Management Studio [duplicate] - sql-server

This question already has answers here:
How to auto daily execute queries SQL Server? [duplicate]
(3 answers)
Closed 3 years ago.
I am using SQL Server Management Studio v17.4
I have a view v_fetch_rates. I have created a table using the command
SELECT *
INTO RATES
FROM v_fetch_rates
My question is how do I update the table RATES on daily basis automatically? Is there a way to do it by existing view or do I need to write stored procedure for this?
I did some googling but it confused me even more.
I have never created a job before so any help/resources to refer would help a lot.

If the issue is that the view is slow (because of its definition or the amount of data it returns) and you want to materialized the data in order to improve performance you can simply create a indexed view.
The idea is simple - creating an index on the view forces the engine to materialized it. Of course, there are various limitations and requirements of having index view. You can find more information in the specified link.
If you just want to have the data in a table and populated in on daily basis, you can:
create simple stored procedure which is truncating the current table and populating the data again calling the view
create a complex routine, which will modify (insert/update/delete) data only if needed

Related

Script multiple CREATE TABLEs in SQL SSMS? [duplicate]

This question already has an answer here:
How do I generate scripts for all tables with single stroke in SQL Server 2000? [closed]
(1 answer)
Closed 3 years ago.
I have a database with many tables that have been periodically updated over the years (not by me). I would like to make CREATE TABLE scripts for all of the tables.
It appears Script table as... only works on a single table at a time. Is there a way to script out all of the tables in a database?
In SSMS, Right Click the Database, go to Tasks -> Generate Scripts.
In the second window, select Select specific database objects and tick Tables:
Choose where you want the results to to go, File, Clipboard or a new Query Window
Check all the settings are correct
Finish. Consume your file/clipboard.

What is the advantage of creating view in SQL database? [duplicate]

This question already has answers here:
Why do you create a View in a database?
(25 answers)
Closed 3 years ago.
Is there any advantage of creating views for tables in SQL, compared to directly query the table?
Views help you hide sensitive columns that you don't want to show certain type of users by limiting the degree of exposure to the underlying tables. You can also wrap joined multiple tables into a single view (virtual table) that can easily be queried as a single table.

Copy tables containing BLOB columns between Oracle Databases [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 6 years ago.
Improve this question
On adhoc basis, we want to copy contents from 4 of our Oracle production tables to QA/UAT environments.
This is not a direct copy and we need to copy data based on some input criteria for filtering.
Earlier we were using Sybase database hence BCP utility worked with charm there. However, we have recently migrated to Oracle and need similar data copy requirement.
Based on the analyses till now, I have analyzed below options -
RMAN (Recovery Manager) - Cannot use as it does not allow us to copy selected tables or filtering on data.
SQLLDR (SQL Loader) – Cannot use this as we have BLOB columns and hence not sure how to create a CSV file for these BLOBS. Any suggesstions?
Oracle Data pump (Expdp/Imbdp) – Cannot use this as even though it allows copying selected tables it does not allow us to filter data using some query with joins (I know it allows to add query but it works only on single table). A workaround is to create temp tables with desired dataset and dmp them using EXPDP and IMPDP. Any suggesstions if I have missed anything in this approach?
Database Link – This is the best approach which seems possible in this use case. But needs to check if DBA will allow us to create links to/from PRD db.
SQL PLUS COPY - Cannot use this as it does not work with BLOB fields.
Can someone please advise on which should be the best approach w.r.t performance.
I would probably use a DATAPUMP format external table. So it would be something like
create table my_ext_tab
organization external
(
type oracle_datapump
default directory UNLOAD
location( 'my_ext_tab.dmp' )
)
as
<my query>
You can then copy the file across to your other database, create the external table, and then insert into your new table via an insert, something like:
insert /*+ APPEND */ into my_tab
select * from my_ext_tab
You can also use parallelism to read and write the files
Taking all your constraints into account, it looks like Database links is the best option. You can create views for your queries with joins and filters on the PROD environment and select from these views through the db links. That way, the filtering is done before the transfer over the network and not after, on the target side.

Insertion large number of Entities into SQL Server 2012 [duplicate]

This question already has answers here:
How to do a Bulk Insert -- Linq to Entities
(4 answers)
Closed 9 years ago.
I'm on a project using Entity Framework 5 and SQL Server 2012. We have a need to insert a large number of rows at once (order of 100k entities). Basically we have a physics program that outputs a large amount of binary data that we then need to process and pull into a SQL 2012 DB. We're using EF5 as the ORM in other places in the application, but I'm doubtful of it's ability to handle this kind of insert in a timely fashion.
We're using a database-first approach where the POCOs generated from the model are passed around throughout the code-base as the primary DTOs.
I would also add that this insert involves multiple tables with foreign key relationships. Is this an issue with the various bulk insert methods out there.
Does anyone have any similar experience with this or a recommended approach?
I would look into the Bulk Insert that is available. Here is a link to some information on it: Bulk Insert. I would also look at SQL Compact Bulk, which was used Here .
Another link where a user submitted his code Stack Link.

How to see what stored procs/functions/triggers rely on a column in a table? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Find a specific column entry in an unknown table in a database?
how to search Sql Server 2008 R2 stored procedures for a string?
Hello I'm trying to figure out a fairly complex SQL Server(2008 in 2000 compatibility) database. There are 3 columns in a table I'm particularly concerned with. I've searched the code of our application and it seems to make no direct usage of these 3 columns but I know somewhere in the database they are populated and used. So it must be in triggers, functions, and/or stored procedures.
What is the best way of figuring out where to look for the code that populates these 3 columns?
If you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).
It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use??

Resources