I am trying to move a table from one schema to another. I have tried this from table design and through TSQL with an ALTER SCHEMA statement (ALTER SCHEMA SchemaName TRANSFER dbo.ObjectName).
I can do this for any schema in my database except one now as it times out in the designer and runs forever in TSQL. It has 7-8 tables in it that I was originally able to put in the schema but now the schema appears locked. How do I debug this? I see nothing in the standard error logs.
Related
I'm doing a project for my DBA class and I've been asked to include the DDL from the database. I've already created the DB Tables and filled them. I tried to recreate the database with only the Tables without the columns filled in, but I cannot find where to get the DDL from. I am not creating this DDL from scratch (I don't know SQL that well). This is supposed to be done completely in Access, but I can't figure out where to get this statement, as there is no SQL view unless you're in Query Design mode. I've looked high and low on Google and I'm beginning to think that there is no way to get the DDL from Access.
I wanted to change a field in a database table to be a calculated field rather than being populated using a trigger.
I am using Entity Framework database first so I added this sql to a migration to carry out the task:
EXECUTE('ALTER TABLE [dbo].[BaseAnsweredQuestions] DROP COLUMN [CalculatedDueDate]
')
EXECUTE('ALTER TABLE dbo.BaseAnsweredQuestions ADD
CalculatedDueDate AS etc...')
This gave me a problem because a couple of indexes are dependent on this field. So I added drop sql for the index before the table changes with recreate sql after the changes.
When I ran the migration on my "staging" database I got an error:
Transaction Log for database is full
And my application would not run at all. I ran a database backup and that appeared to clear the problem, however I want to run the migration on production. How can I prevent the transaction log overflow occurring?
I don't have much experience on SQL replication(SQL Server 2014). My client have a replication process which was created by his previous contractor. It worked well and suddenly it stopped replicating DDL statements couple of days ago. We have not done any change related to replication. When I checked data, subscriber has received up to date data. Only DDL statements have the problem. It uses transactional replication.
When I searched on web it says that the "Replicate schema changes" option need to set as true on Publication Properties.In my case it was already set to true.
Is there anyway for me to fix this and again have DDL statements to replicate as earlier?
Thank you
SQL Server Replication does support schema changes, but not all of them. In your case, CREATE PROCEDURE is not a supported schema change. Why? It's not an article yet, and not marked for replication, thus it cannot be replicated - replication has no way of knowing whether or not you would want that object replicated.
However, if you create the stored proc, then create an article for it, then issue an ALTER PROCEDURE, you will see the change replicated.
Please see article Make Schema Changes on Publication Databases:
Replication supports a wide range of schema changes to published objects. When you make any of the following schema changes on the appropriate published object at a Microsoft SQL Server Publisher, that change is propagated by default to all SQL Server Subscribers:
ALTER TABLE
ALTER TABLE SET LOCK ESCALATION should not be used if schema change replication is enabled and a topology includes SQL Server 2005 or SQL Server Compact 3.5 Subscribers.
ALTER VIEW
ALTER PROCEDURE
ALTER FUNCTION
ALTER TRIGGER
ALTER TRIGGER can be used only for data manipulation language [DML] triggers because data definition language [DDL] triggers cannot be replicated.
Please ensure you read the whole article, to be fully aware of what can be replicated, and under what circumstances.
We recently moved our database to a new server. However, at the time, we did not allow the Code First migrations to create the database. We used another tool to migrate the tables and data. The __MigrationHistory table was not moved during this time. The __MigrationHistory is a system table in our original DB.
I cannot seem to find a way to import or export the __MigrationHistory table so we can allow future migrations to take place.
The only other thought we had, is to have the application recreate the database and migrate the copied data to the new version of the DB. The only issue is we have millions of records to move and it is quite a long process.
I use the following script to move the EF MigrationHistory table from the system tables to the user tables (of a database tree structure):
SELECT * INTO [dbo].[TempMigrationHistory] FROM [dbo].[__MigrationHistory];
DROP TABLE [dbo].[__MigrationHistory];
EXEC sp_rename 'TempMigrationHistory', '__MigrationHistory';
This way I can export the table by choosing standard script/export option under SSMS.
(The complete description of handling this issue is here)
I have the following questions about how transactional replication handles the following. For the sake of example, assume database 'A' is being replicated (via transactional replication) to database 'B'.
If a table in database ‘A’ is dropped, will the table get dropped in ‘B’?
If a table in ‘A’ is renamed, what happens to the table in ‘B’?
If we drop a column in a table in database ‘A’, what will happen to the column in the same table in database ‘B’?
If we rename a column in a table in database ‘A’, what will happen to the column in the same table in database ‘B’?
Is replicating stored procs, views and UDF’s are optional?
Is there any way to avoid all the stored process being created in database ‘B’ as a result of it being the subscriber of a replication?
a. If not, can we at least dictate what schema they are created in?
Most of your questions are answered here: Frequently asked questions for Replication Administrators
You cannot drop a table that is replicated. You have to first drop the article.
You cannot rename a table that is replicated. You have to first drop the article.
Issuing ALTER TABLE … DROP COLUMN at the Publisher, will result in the command being replicated to the Subscriber.
You cannot rename a column "whilst" it is being replicated. You need to remove it from replication first.
Yes, it's optional.
What do you mean by created?
All of these items can be tested very easily by creating a very simple Replication topology on a test server. I suggest you do so in order to both plan for and practice your changes.