sql-drop

How to drop unique in MySQL?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 03:07:22
Create Table: CREATE TABLE `fuinfo` ( `fid` int(10) unsigned NOT NULL, `name` varchar(40) NOT NULL, `email` varchar(128) NOT NULL, UNIQUE KEY `email` (`email`), UNIQUE KEY `fid` (`fid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 I want to drop the unique key on email ,how? Simply you can use the following SQL Script to delete the index in MySQL: alter table fuinfo drop index email; There is a better way which don't need you to alter the table: mysql> DROP INDEX email ON fuinfo; where email is the name of unique key (index). You can also bring it back like that: mysql> CREATE UNIQUE INDEX email ON

How to drop all user tables?

Deadly 提交于 2019-11-28 02:31:22
How can I drop all user tables in oracle? I have problem with constraints. When I disable all it is still no possible. Henry Gao BEGIN FOR cur_rec IN (SELECT object_name, object_type FROM user_objects WHERE object_type IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SYNONYM', 'PACKAGE BODY' )) LOOP BEGIN IF cur_rec.object_type = 'TABLE' THEN EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '" CASCADE CONSTRAINTS'; ELSE EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"'; END IF;

Python sqlite3 parameterized drop table

半世苍凉 提交于 2019-11-27 16:12:26
I have a problem with dropping sqlite3 table in python. I am using standard sqlite3 module. self.conn = sqlite3.connect(...) sql = """ drop table ? """ self.conn.execute( sql, (u'table_name',) ) gives me OperationalError: near "?": syntax error When I change sql to: sql = """ drop table table_name """ it works fine. You cannot use parameters for table names nor column names. Alternatively you could make it a two-step process, e.g.: sql = """ drop table %s """ % a_table_name self.conn.execute( sql ) And if you're doing that you may want to explicitly specify which tables can be deleted...

MySQL DROP all tables, ignoring foreign keys

穿精又带淫゛_ 提交于 2019-11-27 09:55:53
Is there a nice easy way to drop all tables from a MySQL database, ignoring any foreign key constraints that may be in there? Dion Truter I found the generated set of drop statements useful, and recommend these tweaks: Limit the generated drops to your database like this: SELECT concat('DROP TABLE IF EXISTS `', table_name, '`;') FROM information_schema.tables WHERE table_schema = 'MyDatabaseName'; Note: This does not execute the DROP statements, it just gives you a list of them. You will need to cut and paste the output into your SQL engine to execute them. Note, per http://dev.mysql.com/doc

DROP FUNCTION without knowing the number/type of parameters?

柔情痞子 提交于 2019-11-27 06:52:57
I keep all my functions in a text file with 'CREATE OR REPLACE FUNCTION somefunction' . So if I add or change some function I just feed the file to psql. Now if I add or remove parameters to an existing function, it creates an overload with the same name and to delete the original I need type in all the parameter types in the exact order which is kind of tedious. Is there some kind of wildcard I can use to DROP all functions with a given name so I can just add DROP FUNCTION lines to the top of my file? You would need to write a function that took the function name, and looked up each overload

How to drop all user tables?

て烟熏妆下的殇ゞ 提交于 2019-11-27 04:55:11
问题 How can I drop all user tables in oracle? I have problem with constraints. When I disable all it is still no possible. 回答1: BEGIN FOR cur_rec IN (SELECT object_name, object_type FROM user_objects WHERE object_type IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SYNONYM', 'PACKAGE BODY' )) LOOP BEGIN IF cur_rec.object_type = 'TABLE' THEN EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '" CASCADE CONSTRAINTS'; ELSE

SQL Server: drop table cascade equivalent?

狂风中的少年 提交于 2019-11-27 04:37:13
In oracle, to drop all tables and constraints you would type something like DROP TABLE myTable CASCADE CONSTRAINTS PURGE; and this would completely delete the tables and their dependencies. What's the SQL server equivalent?? I don't believe SQL has a similarly elegant solution. You have to drop any related constraints first before you can drop the table. Fortunately, this is all stored in the information schema and you can access that to get your whack list. This blog post should be able to get you what you need: http://weblogs.asp.net/jgalloway/archive/2006/04/12/442616.aspx -- t-sql

SQL: deleting tables with prefix

[亡魂溺海] 提交于 2019-11-27 02:41:44
How to delete my tables who all have the prefix myprefix_ ? Note: need to execute it in phpMyAdmin You cannot do it with just a single MySQL command, however you can use MySQL to construct the statement for you: In the MySQL shell or through PHPMyAdmin, use the following query SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_name LIKE 'myprefix_%'; This will generate a DROP statement which you can than copy and execute to drop the tables. EDIT: A disclaimer here - the statement generated above will drop all tables in all

Does dropping a table in MySQL also drop the indexes?

无人久伴 提交于 2019-11-27 02:02:01
问题 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. 回答1: 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. 回答2:

How to remove all MySQL tables from the command-line without DROP database permissions? [duplicate]

冷暖自知 提交于 2019-11-26 19:17:22
This question already has an answer here: MySQL DROP all tables, ignoring foreign keys 22 answers How do I drop all tables in Windows MySQL, using command prompt? The reason I want to do this is that our user has access to the database drops, but no access to re-creating the database itself, for this reason we must drop the tables manually. Is there a way to drop all the tables at once? Bear in mind that most of the tables are linked with foreign keys so they would have to be dropped in a specific order. Devart You can generate statement like this: DROP TABLE t1, t2, t3, ... and then use