sql-drop

Force drop mysql bypassing foreign key constraint

强颜欢笑 提交于 2019-12-03 01:33:05
问题 I'm trying to delete all tables from a database except one, and I end up having the following error: Cannot delete or update a parent row: a foreign key constraint fails Of course I could trial and error to see what those key constraints are and eventually delete all tables but I'd like to know if there is a fast way to force drop all tables (as I'll be able to re-insert those I don't want deleted). Google aimed me at some site that suggested the following method: mysql> SET foreign_key

Drop a table column

守給你的承諾、 提交于 2019-12-02 12:23:29
Is the following correct? I am getting an error. <?php $form_id = $form->data['form_id']; $query = mysql_query(" ALTER TABLE 'email_history' DROP '$form_id'; ") or die(mysql_error()); ?> Use ` (backtick) to delimit object names in MySQL. Try that ALTER TABLE `email_history` DROP `$form_id`; Note, I don't know php, but you can't parametrise DDL ( ALTER TABLE etc) 来源: https://stackoverflow.com/questions/8689324/drop-a-table-column

SQLPlus is trying to drop package twice

大兔子大兔子 提交于 2019-12-02 02:19:57
While executing scripts in SQLPlus I've encountered a problem: script.sql contains the following lines @some_pkg.pks @some_pkg.pkb drop package some_pkg; / After calling > sqlplus user/password@dbname @script.sql the following messages are in console: Package created. Package body created. Package dropped. drop package some_pkg; * ERROR at line 1: ORA-04043: object SOME_PKG does not exist Please, explain what's happening here. Looks like the package is being dropped twice. Is it possible to avoid the error? The rules of SQLplus command execution basically are: Execute the current text when you

DB2 Drop table if exists equivalent

若如初见. 提交于 2019-12-01 03:02:09
I need to drop a DB2 table if it exists, or drop and ignore errors. First query if the table exists, like select tabname from syscat.tables where tabschema='myschema' and tabname='mytable' and if it returns something issue your drop table myschema.mytable Other possibility is to just issue the drop command and catch the Exception that will be raised if the table does not exist. Just put that code inside try {...} catch (Exception e) { // Ignore } block for that approach. Try this one: IF EXISTS (SELECT name FROM sysibm.systables WHERE name = 'tab_name') THEN DROP TABLE tab_name;END IF; search

How do I drop a column with object dependencies in SQL Server 2008?

ⅰ亾dé卋堺 提交于 2019-11-30 10:53:39
The error message I'm obtaining when trying to drop a column: The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'. Msg 5074, Level 16, State 1, Line 43 ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column. I have already tried to find the default constraints, as described here: SQL Server 2005 drop column with constraints Unfortunately without any success :( The line returned is: fkKeywordRolleKontakt 2 814625945 0 defEmptyString And I cannot remove either of fkKeywordRolleKontakt and defEmptyString . What is the correct way

Is there a MySQL command to implement something like “drop tables except t1,b2”?

爱⌒轻易说出口 提交于 2019-11-29 16:40:54
I want to keep t1,t2 and drop all other tables. You can use information_schema to find table names, and even format the results as a bunch of DROP statements. SELECT CONCAT('DROP TABLE ', TABLE_NAME, '; ') FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name NOT IN ('foo', 'bar', 'baz'); (The DATABASE() function returns the currently use 'd database.) Using PREPARE and EXECUTE , you could even avoid copy & paste, and (in MySQL 5.0.13 and later) write a stored procedure to do this. You could use mysqldump to generate a list of DROP TABLE statements, filter out the ones

How do I drop a column with object dependencies in SQL Server 2008?

岁酱吖の 提交于 2019-11-29 16:07:07
问题 The error message I'm obtaining when trying to drop a column: The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'. Msg 5074, Level 16, State 1, Line 43 ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column. I have already tried to find the default constraints, as described here: SQL Server 2005 drop column with constraints Unfortunately without any success :( The line returned is: fkKeywordRolleKontakt 2 814625945 0

Cannot create a new table after “DROP SCHEMA public”

℡╲_俬逩灬. 提交于 2019-11-28 19:09:22
Since I wanted to drop some tables and somebody suggested the below and I did it: postgres=# drop schema public cascade; DROP SCHEMA postgres=# create schema public; CREATE SCHEMA Then I got problem when creating a new database, such as: postgres=# create database test; CREATE DATABASE postgres=# \c test You are now connected to database "test" as user "postgres". test=# create table hi(id int primary key); *ERROR: no schema has been selected to create in* You can see I got error ERROR: no schema has been selected to create in* How can I restore the public schema? I suggest people never do

MySQL bulk drop table where table like?

自作多情 提交于 2019-11-28 16:53:33
DROP TABLE ( SELECT table_name FROM information_schema.`TABLES` WHERE table_schema = 'myDatabase' AND table_name LIKE BINARY 'del%'); I know this doesn't work! What is the equivalent for something like this in SQL? I can whip out a simple Python script to do this but was just wondering if we can do something with SQL directly. I am using MySQL. Thank you! Devart You can use prepared statements - SET @tables = NULL; SELECT GROUP_CONCAT('`', table_schema, '`.`', table_name,'`') INTO @tables FROM information_schema.tables WHERE table_schema = 'myDatabase' AND table_name LIKE BINARY 'del%'; SET

Does dropping a table in MySQL also drop the indexes?

岁酱吖の 提交于 2019-11-28 07:55:25
It's not explicitly mentioned in the documentation ( http://dev.mysql.com/doc/refman/6.0/en/drop-table.html ). I ask because I just saw a curious database migration in a Rails project where the developer was removing all the indexes before dropping the table, and that seemed unnecessary. Yes, it does. However, if you have foreign key constraints such as RESTRICT that ensure referential integrity with other tables, you'll want to drop those keys prior to dropping or truncating a table. tvanfosson Yes it would drop the index. There's no reason to keep the index if the underlying table isn't