I am trying to convert my DB to be Azure SQL V12 compatible which requires removing all file groups except for PRIMARY. I've migrated all PK and INDEXES to be on primary. Now I have only some tables that specified TEXTIMAGE_ON that are not in the primary file group. here is the current table definition:
CREATE TABLE [dbo].[HistLocation](
xxxx
) ON [PRIMARY] TEXTIMAGE_ON [HIST]
I tried doing the steps in this link: https://www.jitbit.com/alexblog/153-moving-sql-table-textimage-to-a-new-filegroup/
But when I try to save the file it states:
"Saving changes is not permitted, The changes you made require the following tables to be dropped..."
Is there another way around this?
I would strongly suggest that you use T-SQL to make changes, or at the very least, preview the scripts that the Designers generate before committing them. However, if you want to do this in the designer, you can turn off that lock by going to Tools...Options...Designers..Table and Database Designers.. and unclick the "prevent saving changes that require table re-creation".
That lock is on by default for a reason; it keeps you from committing some change that is obfuscated by the designer.
EDIT: As noted in the comment below, you can't preview the changes unless you disable the lock. My point is that if you want to use the table-designer to work on a table with this feature disabled, you should be sure to always preview the changes before committing them. In short, options are:
BEST PROCESS: Use T-SQL
NOT GREAT: Disable the lock, use Table Designer, and ALWAYS preview changes
CRAZY TALK: Click some buttons.
Related
Currently I have CDC enabled on a table DATA_Sale. I want to disable the logging of any new changes but want to keep the CDC for records. Is this possible?
The process of disabling CDC on your table will cause the corresponding system table that's been capturing the changes to be dropped, as noted in the documentation that #SeanLange posted in the comments, sys.sp_cdc_disable_table.
But knowing that the system table will go away just means you have to plan for that.
First, you probably want to stop capturing new changes, unless you have other capture instances running:
EXEC sys.sp_cdc_stop_job #job_type = N'capture';
Now make a copy of the system table, and port your data over to it. 'SELECT ... INTO ...` will do. You can tweak the structure later if you need to.
Then go ahead and disable the capture.
I am working on Oracle10.2g database for a web project. I had exported full Schema objects of a database from a remote system in a file(some-file.dmp). Then I wanted to import the contents of file into another database on the local system. The process worked perfectly.
However, I accidently imported the file contents(including tables,views etc.) into SYS user. So, the SYS user is now overcrowded with around 1500 unwanted objects.
I know I can drop the objects individually, but, that's a tiresome effort. Now, I was wondering if there is any way that I can kind of undo the process and remove the unwanted objects(remove the tables,views etc. from SYS user that were mistakenly imported)?
EDIT :
The imported objects include in particular
Tables(Obviously including FK Constraints)
Views
Indexes
Packages
Procedures
Functions
Sequences
Triggers
Java Code
So, they are inter-related to one another. Any ideas or Advice greatly appreciated!
You can try querying DBA_OBJECTS and looking for any that are owned by SYS and recently created. For example, the following lists all objects that were created in the SYS schema today:
SELECT object_name, object_type
FROM dba_objects
WHERE owner = 'SYS'
AND created >= TRUNC(SYSDATE)
You can then use this to generate some dynamic SQL to drop the objects. That should save you dropping them manually.
Note however that there may be some objects that have been recently created and should be owned by SYS, so double-check what it is you're dropping before you drop it. (On my Oracle 11g XE database, the newest objects in the SYS schema were index and table partitions created about a week and a half ago.)
I don't know what types of objects you have, but there will be some dependencies between object types. In particular, you can't drop a table if another table has foreign-key constraints pointing to it. This answer provides some PL/SQL code to disable all constraints on a table, which you can adapt to drop all constraints, or just drop all foreign-key constraints, if you need to.
Also, if a table column uses a type, that table will need to be dropped before dropping the type. Similarly, you may have to take care if types have dependencies on other types.
Other things to be aware of:
You don't need to drop package bodies, just drop the packages and the bodies will go with them.
You don't need to drop triggers on tables and views: the triggers go when the table or view is dropped. Similarly, dropping a table drops all of the indexes on that table.
Views, procedures, functions and packages may depend on other objects but they shouldn't stop those other objects from being dropped. The views/procedures/functions/packages should become invalid, but if they're going to be dropped anyway that doesn't matter.
You don't specify what other types of object you have, so there may well be other issues you encounter.
EDIT: in response to your updated question:
You can drop the objects in the order you specify, once you've dropped the FK constraints. The tables will be the hardest part: once they're all gone everything else should be straightforward.
You don't need to drop indexes as they get dropped automatically when you drop the tables.
You don't need to drop triggers on tables or views as these get dropped automatically when you drop the view or table. (I don't know whether you have any other triggers such as AFTER LOGON ON DATABASE, but such triggers might not be included in exports anyway.)
I only have Oracle XE, which doesn't support Java, so I can't be sure of the exact incantation necessary to drop Java classes. The Oracle documentation for DROP JAVA may be of some help to you.
Is there any way to force drop a table in sybase which is currently in use ?
Or any way to get rid of the lock.
Force drop will be a better option. But does a force drop exist ?
Sybase is totally online, and multi-user, no need for single user mode.
If you have enough privilege you can perform various actions. None of these actions "break data or database or referential integrity" that id already defined in DDL:
if the problem is that the table (not pages) is locked, and you want you eliminate the table lock, which is preventing other users accessing the table, kill the spid. sp_lock will identify the server process id.
if you actually want to drop the table, but it is locked, first kill the spid; then drop the table.
(There is a "force drop" command, but that is undocumented and unsupported; more important it is for special cases, not necesary for your case.)
No you can't because if it does, Sybase would break the integrity of the database.
Imagine : an user is reading datas from a table and at the same time another is destroying this same table !!
If you want to force it, you have to turn on the database into "single-user" and after that no one -but you- will can connect to the database and do what you want...
try http://www.tek-tips.com/viewthread.cfm?qid=220392&page=49
for switching to single user.
I'm wondering if is there a way to force MSSQL Management Studio to produce a script like this:
ALTER TABLE Mytable
ADD MyCol bit NOT NULL
CONSTRAINT MyColDefault
DEFAULT 0 WITH VALUES
ALTER TABLE [dbo].Mytable
ALTER COLUMN MyCol2 int NULL
GO
when I alter a very simple property of a column on a table.
If I do this in the designer and ask for the produced script, the script doesn't do such simple tasks, but instead copies all the data in a tmp table, drops the original table, renames the tmp table with the original table name. And, of course, drops and recreates every constraint and relationships.
Is there any option I can change to change this behaviour? Or, this may be possible, is there some danger I don't see in using the simple ALTER TABLE above?
thanks.
Yes you can!
In SQL Server Management Studio, go into the table design mode for the table in question, and make your changes. However: do not click on the "Save" button, but instead right-click in the table design view, there should be a "Generate Change Script" item at the end of your context menu.
Click on that menu item and you'll get presented a pop-up dialog box which contains the T-SQL script needed to do those changes that you made to the table in the designer. Copy or save that T-SQL code, and cancel out of the designer, and voila - you have your change script!
UPDATE: Marco, sorry, I don't think there's any option to change the default behavior, at least not right now. You might want to file an enhancement request with Microsoft on Microsoft Connect to propose that - good idea, I would think!
You can't change the behaviour, it's just that the default script it creates is not always the most efficient. It creates scripts in a format it knows will work, although frequently the results will be slow and resource-heavy. I recommend you get used to creating the script for all changes yourself as you can better optimize it. There's nothing wrong with what you've created (providing you have no existing constraints/dependencies on MyCol2 that would be invalidated by it becoming a nullable int)
Just to augment #marc_s's answer. In case you still can't generate the change script 'cause your table needs to be recreated, you need to go to Tools -> Options and under Designers -> Table and Database Designers unmark the option Prevent saving changes that require table re-creation.
easy! just go to Tool->Option, then the Designer node and select Table and Database designer so that you can uncheck the Prevent saving changes that require ... checkbox.
Now you can make any chage on your tables design!
Whenever I make changes to a table structure in SSMS, there is a alert raised:
saving the changes is not permitted.the changes u have been made to the following tables to be dropped and recreate..
Some changes cause a table to be dropped and recreated. One such example is adding a column to the middle of a table rather than to the end.
You can do one of two things:
Option 1
Use TSQL to make your changes and add the column to the end (or the equivalent non table-drop option for your specific edit)
Option 2
Alter the default behavior of SSMS (warning - this is a very dangerous thing in production environments)
Open SQL Server 2008 Management Studio (SSMS). In the menu, go to Tools / Options. In the Navigation pane, expan Designers, and select "Table and Database Designers".
Under Table options, uncheck “Prevent saving changes that require the table re-creation” option and click OK.
I've seen those kinds of messages most often come up when the changes you are making could potentially cause data to be truncated. So, if you were changing an nvarchar(20) to nvarchar(10), that would come up. It doesn't matter if the column only contains data that is 2 characters long, it only looks at the data type. There may be other reasons and other flavors of that message, but mostly they follow the same reasoning: If the change would cause the table to be more restricted in the data it could hold, it wants to do radical surgery.