How to save a query in SQL Server using a trigger? - sql

How to save a query in SQL Server using a trigger?
I have a database that supplies different applications. I have detected that one of them is updating a column to null. I want to save the query that does it, so I can know which application is having this error.
Is there a way to save the query that executes a trigger?

Related

SSIS insert recrods from Oracle to SQL and even process them

Thanks for answering...
I am new to SSIS and I have below requirement:
We are getting bulk records from Oracle based on some criteria.
I need to insert all these bulk records first to an audit table in SQL server The tables has only few columns. the reason for this is we will get to know how many records in each cycle we have got from oracle and if they are pilling up what is the exact reason.
After inserting in audit table, I need to process them one by one in SQL server and at the end of processing I would be either accepting the record and inserting the entire record in SQL serever or rejecting the record in SQL server based on business condition.
Currently to implement this I have first added a Data flow task in SSIS package which selects few columns(which are required by Audit table) from the Oracle and inserts them to SQL server after conversion. Than I am again getting the records from oracle using SQL execute task and processing them one by one using for each container in sql server.
As mentioned above I am making twice the call to Oracle, I am not able to reduce this to one?
can someone please guide me how can I achieve this?
Thanks in advance.
If you have the data already in SQL (you did a bulk copy in your audit table) you can take the data from there and do the insert in the table you want.
Instead of reading the data from Oracle twice, you can use your SQL Execute Task to manipule the data in SQL. You can make the insert statement from here to the final table.

SQL Server: Create a duplicate of a database without the data

I have a database called AQOA_Core with huge amount of data.
I have a newly created database called AQOA_Core1 which is basically empty. I want to write a query to duplicate AQOA_Core to AQOA_Core1 without the data. I guess to be precise I want to create a skeleton of the primary database into the secondary database.
PS: I use Toad for my database operations.
You can use SQL Server Script Wizard for scripting database objects. You can exclude data, and select the database object types you want to include in your script
Please check the SQL Server guide I referenced above,
I hope it helps you

Does Modifying Data in Access Table Modify Data in an ODBC-connected Oracle SQL table?

I am new to access. I am using a tool/access database someone built, and it has an ODBC connection to an Oracle SQL database in it.
There are different queries on the side panel, and some of them are delete queries.
If I run these delete queries will they just modify data in my local access database without modifying the data in the Oracle Database?
Yes these will change something in the database whether its linked with another access database table or oracle table and within the database. To review the query you can open the queries in design view and run a normal select query so you can see what the queries are deleting. You can have a normal table image and or globe with a arrow in front pointing towards the table then its linked. A lot of times when I am testing I just run select queries and then I make a copy of what I will be deleting just in case anything goes wrong.

For a Front end access user interface connected to a backend SQL server, do I create new queries for tables in the SQL server or Access frontend?

I am a new database intern working with a access front end and SQL server backend database. The database was custom made for the company. One of my assignments is to take scripts and apply them to make four new tables. I am aware that I need to make a new query for each new table but I don't know if I should make the query in SQL server management studio or the frontend access program. I have tried copying and pasting the given scripts into a new query in access but I get an error message "invalid SQL statement expected 'DELETE', 'INSERT'...". I decided to try to break done the program a little bit and tested the first line
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =OBJECT_ID(N'[dbo] .[FK_tblInstrumentInterfaceLog_tlkpInstrument]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblInstrumentInterfaceLog]'))
but the same error message keeps popping up. I even tried just SELECT * FROM sys.foreign_keys, and I got the error message "could not find file...". I am very much a beginner and any guidance would be appreciated.Basically am I supposed to be applying these scripts the server SQL database or on the front end access program?
Are you using a pass-through query? i.e. not just a select query. Access needs to know where to send the query and since you are using TSQL not Access SQL this needs to be executed on the server.
Normally when you query a linked table the information of how to get the data (the connection string) is tied to the table. But for this kind of query you'll probably need to tell Access explicitly. Unless you are using an ADP/ADE, then the connection info travels with the program not the table.
As a general rule, you use SQL management studio (SSMS) to create and run those scripts. So the general accepted approach here is such scripts will not be placed in the front end. As noted such scripts if for some reason must be placed in the front end, then you have to create them as pass-though, but EVEN in this case you want to use the SSMS to create such quires.
So the answer here is you create the new scripts and make table queries in the back end, or in this case using the SQL server management studio.
The syntax checking, query editor etc. in recent versions of SSMS now has auto-complete etc. and you can test/write/update those scripts in SQL server. Once you have such a query or even several of them, then the resulting “several” statements can be pasted into a front end query that been created as pass-though. If you do not use a pass-though query, then you are creating and using and assuming client side SQL (JET (now called ACE)).
The client side has it own version of SQL syntax, and it is NOT 100% compatible with the SERVER SIDE. If you writing SQL in the client that is NOT pass though, then you using a linked table to SQL server. These linked tables thus will use local (JET/ACE) based SQL queries. The ODBC driver thus translates this SQL into server side compatible syntax. However the JET/ACE sql syntax is very limited when compared to SQL server and no server side commands exist in this SQL syntax for the client data engine (JET/ACE)
So for many quires, you will and can simply build such queries using the Access query builder.
However for SQL that needs to run 100% server side then such quires has to be setup as pass-though and are in most cased built + tested using SSMS.

Is there an Access equivalent of the SQL Server NewId() function?

I have written SQL statements (stored in a text document) that load data into a SQL Server database. These statements need to be repeated daily. Some of the statements use the NewId() function to populate a keyed field in the database, and this works fine.
While I'm in the process of writing an application to replicate these statements, I want to use Access queries and macros instead of copying and pasting queries into SQL Server, thus saving me time on a daily basis. All is working fine but I can't find any function that will replace the SQL Server NewId() function. Does one exist or is there a work around?
I'm using SQL Server 2005 and Access 2007.
On top of matt's answer, you could simply use a pass-through query and just use your existing, working queries from MS Access.
A solution would be to insert the stguidgen() function in your code, as you can find it here: http://trigeminal.fmsinc.com/code/guids.bas https://web.archive.org/web/20190129105748/http://trigeminal.fmsinc.com/code/guids.bas
The only workaround I can think of would be to define the column in your access database of type "Replication ID" and make it an autonumber field. That will automatically generate a unique GUID for each row and you won't need to use newid() at all. In SQL server, you would just make the default value for the column "newid()".
Again, there seems to be confusion here.
If I'm understanding correctly:
You have an Access front end.
You have a SQL Server 2005 back end.
What you need is the ability to generate the GUID in the SQL Server table. So, answers taht suggest adding an AutoNumber field of type ReplicationID in Access aren't going to help, as the table isn't a Jet table, but a SQL Server table.
The SQL can certainly be executed as a passthrough query, which will hand off everything to the SQL Server for processing, but I wonder why there isn't a default value for this field in SQL Server? Can SQL Server 2005 tables not have NewId() as the default value? Or is there some other method for having a field populate with a new GUID? I seem to recall something about using GUIDs and marking them "not for replication" (I don't have access to a SQL Server right at the moment to look this up).
Seems to me it's better to let the database engine do this kind of thing, rather than executing a function in your SQL to do it, but perhaps someone can enlighten me on why I'm wrong on that.