Transact SQL :: DDL Trigger On Table Schema Change
Oct 16, 2015Is to Possible to Create a Triggers to capture Schema (alter table, Drop table) Changes only for certain tables.I don’t want schema change for entire database.
View 7 RepliesIs to Possible to Create a Triggers to capture Schema (alter table, Drop table) Changes only for certain tables.I don’t want schema change for entire database.
View 7 RepliesI have created a table on SQL Server from SAS. The table gets created fine. However, the table schema has my user ID in it (AD-ENTmyuserid.Table1). How can I change the schema to dbo.(dbo.Table1)? It's fine if I have to make this change in SQL Server Management Studio.
View 4 Replies View RelatedHello Everyone,
I am working on a dtsx package wherein i am sending the data from OLE DB Source (SQL Server) to OLE DB Destination (Oracle). For development purpose i use DEVLOPMENT environment on oracle but for unit testing i have to use QA or Some other Schema. when i use DEVELOPMENT Schema in ole db destination, tables are accessed under Schema name eg. "DEVELOPMENT"."EMPLOYEE", but when i m chenging schema name to QA table names are not changing as "QA"."EMPLOYEE". Data Flow Task is pushing the data to DEVELOPMENT environment only.
Can Anyone suggest me any remedy for it ?
Or this is one more BUG in SQL Server 2005.
Advice and suggestions are highly appreciated !
Thanks
I am still having problem with making View automatically updates itself when the underlying table schema changes. Running sp_recompile on the view table doesn't seem to work either, as I am still getting old format from the view (in Design mode the view returns the right info, but not when I open the View by doing Open View) even though the underlying schema has changed. Right now I find that I have to go into the View and change it a bit to force a recompilation.
And even if sp_recompile does, it would require that I manually do it each time I change a table. Any idea?
Hi all,
I'm admitedly a bit new to the world of replication, so please bear with me. I've got two SQL Server 2000 servers running in different locations. Server A does transactional replication over a push subscription to server B. If I need to make a minor change to one of the replicated tables (for example, dropping a no longer used column or changing a varchar field's length) do I need to drop the subscription, make the changes and then re-initialize the schemas and data?
For minor changes, I really hate having to knock out the site runnign off server B while the subscription is re-initialized and data is bulk copied back over. If I want to just make the changes manually on both servers will that cause problems down the line?
Any help is greatly appreciated.
tia.
-m
we have a table in our ERP database and we copy data from this table into another "stage" table on a nightly basis. is there a way to dynamically alter the schema of the stage table when the source table's structure is changed? in other words, if a new column is added to the source table, i would like to add the column to the stage table during the nightly refresh.
View 4 Replies View RelatedIn CLR integrated trigger:
If I want to make a trigger:
- For Insert
- With name: NewEmployeeInserted
- On table dbo.Employees
I add the following attribute above the desired .net method logic:
[SqlTrigger(Event = "For Insert", Name = "NewEmployeeInserted", Target = "Employees")]
How to make a trigger on for example: Production.Employees table?
where Production is the schema where this table resides.
Thank you.
How can I easily identify who dropped a table?
View 8 Replies View RelatedHello,I have created the following trigger:CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATEASDECLARE @foobar varchar(100)SELECT @foobar= foobar FROM insertedIF ( @foobar = 'foobar') INSERT INTO LogTable (LogText) values ('Found foobar')ELSE INSERT INTO LogTable (LogText) values ('Did not find foobar')GOBasically, the trigger monitors the values begin put in the foobar field,and acts accordingly based on what it finds. In practice, my needs are abit more complex (the trigger will be programmatically generated, based ona set of rules) but the principle is much the same.ErrorTable is defined as :create table LogTable (LogText varchar(128))UserDefinedFields is a table whose definition may change depending on theuser's needs, but for now assume it contains a varchar column calledfoobar.My problem is that if the user's needs change, and they remove the fieldfoobar, the trigger causes all subsequent inserts/updates to fail with anerror indicating the column foobar doesn't exist. (Which makes sense ofcourse!)CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATEASDECLARE @foobar varchar(100)if not exists (select * from syscolumns sc inner join sysobjects so on sc.id = so.idwhere sc.name = 'foobar'and so.name = 'UserDefinedFields') BEGININSERT INTO LogTable (LogText) values ('Error : Foobar column does not exist!')RETURNENDSELECT @foobar= foobar FROM insertedIF ( @foobar = 'foobar') INSERT INTO LogTable (LogText) values ('Found foobar')ELSE INSERT INTO LogTable (LogText) values ('Did not find foobar')GOI'd be happy with the above 'flavor' of solution (bailing, or logging anerror and bailing, when we hit unexpected problems) as long as theinserts/updates don't fail otherwise. Perhaps I can nest a transaction, orsupress a RAISEERROR or something?The cleanest solution would probably be to change a bunch of clientsoftware such that it won't remove the foobar field if this field isneeded for a trigger (foreign key constraints based on the set of rulesI'm using are a nice and intuitive solution). Unfortunately, that doesn'twork well with my timeframe (done by thursday) as changing the clientsoftware is impossible by then. Any ideas or suggestions? Platform isWin2k, SQL 2000 Enterprise (I think enterprise, certainly 2000).thanks,Dave
View 6 Replies View RelatedI have a simple query which is taking about 2.5 minutes to execute. What can be done to speed it up ? I cannot change the table structure. even without the group by, and without the float and division, it takes about 2.25 minutes.
Select 'SV00302' as FileSource,
[Service_Call_ID],
sum(0) as ActualHours,
sum(cast([Estimate_Hours] as float)/100) as EstHours,
max(MODIFDT+Modified_Time) as ModifiedDateTime
[code]...
I have 900000 rows of data in a table and a sample of it is as shown below.Now I need to convert data into the format shown.
View 6 Replies View RelatedChange structure of a User Defined Table Types
field
([idConteudo] [int]
NULL) to
([idConteudo] [BigInt]
NULL)
Or really should drop and create again?
CREATE TYPE [dbo].[tbProjeto] AS TABLE(
[dsConteudo] [varchar](64) NOT NULL,
[idConteudo] [int] NULL,
[dtConteudo] [datetime] NULL DEFAULT (getdate())
)
GO
Existing table structure is below:
Table name: Student
Columns in Student are below:
Student_Id
Subject_Id
Quarter
Col1
Col2
Combination of Student_Id, Subject_Id and Quarter columns is the primary key. One student can take one subject in a quarter. Now the new requirement is a student can take multiple subjects in a quarter. So need to add another table like below:
NEW table name: Student_Subject and
column are below:
Student_id
Subject_Id
Quarter1
All the above three columns combination is primary key.
After the new table Student_Subject created,
remove Subject_Id column
from Student table.
When the user clicks on a button after selecting multiple subjects and provide col1 and col2 data then one row gets inserted into Student table and multiple rows gets inserted into Student_Subject table.
Is there any other table design that satisfies one student can take multiple subjects in a quarter?
I have 5 tables that are joined respectively,
Each one of the tables listed below has a “CreateDateTime” and “UpdateDateTime” fields, I need to get yesterday changes, I can get any record where either CreateDateTime or UpdateDateTime is greater than midnight yesterday butI need to watch dates on all of the tables so I need to do atleast 10 date checks.
If any table shows an updated or created record, I need to gather ALL of the information for that customer. So, if my name didn’t change (SCUS table), but my email does (SEML table), I have to pull out both the SCUS and SEML tables (and the others, of course). So It may not be simple WHERE clause, How can I achieve this:
SELECT
SCUS.CUSFULLNAME
,
SCUS.CUSMIDDLENM
,
SCUS.CUSLASTNM ,
[Code] ....
In y sql server table has millions of records available. I don't want to drop the tables.
My requirement is I want to change the column order of an existing table. some tables I am able to saving on design window Like Below image.
Even I had generate a script and using that script trying to execute on Management Studio but unable to saving the new column orders. I am getting the Timeout expired error after couple of minutes. How can we save the orders without dropping the table !
Suppose you have a simple DML "execute as..." trigger that looks like this:
CREATE TRIGGER dbo.myTrigger
ON dbo.myTable
WITH Execute As Owner
AFTER INSERT
AS
[code]...
which runs as "owner" so that the user inserting into "myTable" won't have the privs to edit the audit table.How does one capture the identity of the user whose insert statement caused the trigger to fire? I've tried "current_user" and "system_user" without success when "execute as ..." is used: they each return a value not related to the identity of the user running the original insert.without an "execute as" clause, what prevents a user from adding to or editing the audit table directly?
How can i pass my .net application's Userid to the trigger? I have a audit trail trigger on myTable. I dont know how to pass the userid (not the sql server user) to the trigger when a user delete a record from the application(.NET Application).
The trigger saves the modifications on the table including the userid of one who does the changes.
For our ETL process, we maintain a TransformationList table that has the source view and the destination table. Data is copied from the view into the table (INSERT INTO). I am trying to find column names in the Views that are not column names in the associated Table.
In the below example, want to end up with three records:
1, View1, Column4
2, View2, Column4
2, View2, Column5
I have it almost working, except that there is a table, ChangeColPrefix table, that is used by the ETL process to change some of the view's column name prefixes. Some of the source views have column names with prefixes that do not match the destination table column names. Say view SouthBase has all the column names prefixed with SB - like SBAcct, SBName. And the Destination table of Area District has ADAcct, ADName. There would be a row in the ChangeColPrefix for SouthBase, SB, AD, 1, 2 that would be used by the ETL process to create the INSERT INTO Area District From SouthBase.
I need to use this ChangeColPreifx to find my unmatching columns between my source views and destination tables. With out that table SBAcct and SBName from SouthBase will not appear to match the columns of ADAcct and ADName, but they do match.
I want to end up with these three records as non-matching:
View1, Column4
View2, Column4
View2, Column5
View1 has Salumn2 and View2 has Salumn5, and they must be changed to Column2 and Column5 as per the ChangeColPrefix table before running the Select from INFORMATION_SCHEMA.COLUMNS EXCEPT Select from INFORMATION_SCHEMA.COLUMNS looking for unmatched columns.
/***** Set Up Test Data *****/
-- Create 2 test views
IF EXISTS(SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View1]'))
DROP VIEW dbo.[View1]
GO
CREATE VIEW View1
AS SELECT '1' AS Column1 , '2' AS Salumn2 , '4' AS Column4;
[Code] ....
Hello,
I need to know if the anyone has had success using any sort of tracking tool to manage schema in SQL 7. I'm responsible for several SQL servers, each with upwards of 10 databases - most still in deelopment phase. We use Erwin to store our models and Visual sourcesafe for stored procs and sql scripts.
But now as a Dba I'm looking either:
(1) create a custom database to keep track of schema changes (as they movefrom development to test to prod). OR
(2) buy a 3rd party tools to keep track of schema changes? Platinum?
It's getting too much for a single Dba to manage a busy devel shop with 20 db's. Schema is comming in too often. Only some of our db's are in Erwin.
thanks,
Hi,
View 12 Replies View RelatedIs it possible to turn off transaction logging when making a table schema change? For example, when expanding a varchar field from 10 to 40 characters? This is occurring on a hosted site for a table with about 150,000 records. The db size is 200 Mb. If I try this normally with transaction logging enabled, I get the dreaded log file is full message, even if I first truncate it.
I was thinking about doing the following instead:
taking the db offline
creating a backup
disabling logging
change the schema
re-enable logging
put db back online
If a problem occurs during the schema change, I would just restore from the backup. Please let me know the following:
Is it possible to turn of the transaction logging for the schema change?
Do you see any problems with the above.
Alternatives?
One alternative is to look into increasing the db size. A second is to add a new field (named temp) to the table, copy the old field to the new field, delete the old field, add another field (with the original field name) with the new schema, copy the temp field to the new field, and finally delete the temp field. This should require less space in the transaction log. Unfortnately, it could possibly affect some linked Access databases with the new field order.
Thanks in advance.
There is a report when you click servername, report and run SCHEMA CHANGE HISTORY
I had my SQL 2005 running for a few weeks and this is many listed from day started is there a way to recycle this and clean it up on a weekly basic
Simple question, I hope. I need to add a column to a table of a database that is mirrored. How do I have to do that? Do I need to stop mirroring? Is it sufficient to simply pause mirroring? If I make the change on the principal db, what do I need to do the make the same change on the mirror?
Thanks,
How can I keep schema changes in the subscriber's database when I replicate the snapshot from the publisher?
I just want to move data from a remote server, but it seems that the tables are being dropped which is not good as we use the subscriber as a development box.
Please advise
Hi.
I am trying to get the schema in which the trigger is created within the CLR code.
1)create a new schema MySchema.
2) created a table MySchema.MyTable
3) created the assembly and trigger ( create trigger MySchema.MyTrigger on MySchema.MyTable..... ) Trigger writes to another table MySchema.MyLog.
Code works fine if I hardcode Myschema.MyLog in the CLR but fails when I say just MyLog.
So how do dynamically get the trigger's schema name ?
Thanks for your help.
Nach
Hi,Is there a way I can change schema name on tables and stored procedures? How do I do this?I´m very news to SQL and .netThanks
View 1 Replies View RelatedHi,
While i trying to drop the user,i getting the following error:
(Microsoft SQL Server, Error: 15138)"
Now,i wanna change the owner of that schema,Which is associated with the schema,which i am trying to delete.
How to transfer the owner?
Plz help me.
Hi all. I'm mapping FKs in a DataWarehouse and I'm wondering if there is a way to change the schema of a database diagram from dbo.
Thanks,
Charlie
Question re Merge rep (pull) and processing order. We have a group of changes associated with an app upgrade, the scripts run fine on the publisher. Part of the change includes creation of a new table , followed by altering a view to use new table.Following the change at the publisher, when the sync is kicked off from the subscriber, it fails - the alter of the view throws an'invalid object' error with regard to the new table. Seems as if the view alter is attempted before the dependant table has been created.
I have tried to amend the processing order of the view using sp_changearticle, which executes (quickly) with a 0 return code.But it is to no avail , the error still occurs. is it possible to change the processing order for a view article , which will be applied to schema changes ? Have
One of our databases has at some point in its dark past had the owner of the guest schema changed to be a named user, rather than the default guest user. Correcting this feels like it would be easy enough by running the following...
ALTER AUTHORIZATION ON SCHEMA::guest TO guest
but that results in..
Msg 15150, Level 16, State 2, Line 3
Cannot alter the schema 'guest'.
I realise the guest schema is a special one, and cannot be dropped, but I'm not trying to do that. End goal is to export the database to a SQL Azure DB, and this guest schema assignment is blocking that process from completing.
can a sql server 2000 snapshot replication
solution handle a schema change.
as far as i know i can't drop a table involved in replication
I have a SQL script to insert data into a table as below:
INSERT into [SRV1INS2].BB.dbo.Agents2
select * from [SRV2INS14].DD.dbo.Agents
I just want to set a Trigger on Agents2 Table, which could delete all rows in the table , before carry out any Insert operation using above statement.I had below Table Trigger on [SRV1INS2].BB.dbo.Agents2 Table as below: But it did not perform what I intend to do.
USE [BB]
GO
/****** Object: Trigger Script Date: 24/07/2015 3:41:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
[code]....
I have a table where table row gets updated multiple times(each column will be filled) based on telephone call in data.
Initially, I have implemented after insert trigger on ROW level thinking that the whole row is inserted into table will all column values at a time. But the issue is all columns are values are not filled at once, but observed that while telephone call in data, there are multiple updates to the row (i.e multiple updates in the sense - column data in row is updated step by step),
I thought to implement after update trigger , but when it comes to the performance will be decreased for each and every hit while row update.
I need to implement after update trigger that should be fired on column level instead of Row level to improve the performance?