sql-drop

Dropping a column with a foreign key

亡梦爱人 提交于 2020-01-01 12:06:10
问题 On my mysql DB with inno_db engine, I have a table with a foreign key. I want to drop the column (along with the foreign key and the associated index of course - i don't need the whole column!) Now, simply dropping it yields an error: General error: 1025 Error on rename of '.\road_dmy#sql-19d8_2be' to '.\road_dmy\contact' (errno: 150) It sounds like this is a known issue. http://bugs.mysql.com/bug.php?id=15317 But anyway, what should i do to drop this column? I'm very sure it's possible

SQLPlus is trying to drop package twice

大憨熊 提交于 2019-12-31 03:05:15
问题 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

Python sqlite3 parameterized drop table

≯℡__Kan透↙ 提交于 2019-12-28 04:31:10
问题 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. 回答1: 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

DB2 Drop table if exists equivalent

血红的双手。 提交于 2019-12-19 05:16:42
问题 I need to drop a DB2 table if it exists, or drop and ignore errors. 回答1: 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. 回答2: Try this

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

核能气质少年 提交于 2019-12-18 09:24:54
问题 I want to keep t1,t2 and drop all other tables. 回答1: 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

Cannot create a new table after “DROP SCHEMA public”

*爱你&永不变心* 提交于 2019-12-17 22:27:03
问题 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

MySQL bulk drop table where table like?

笑着哭i 提交于 2019-12-17 21:52:31
问题 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! 回答1: You can use prepared statements - SET @tables = NULL; SELECT GROUP_CONCAT('`', table_schema, '`.`', table_name,'`') INTO @tables FROM

DROP All Views PostgreSQL

随声附和 提交于 2019-12-13 14:46:17
问题 How I can Delete All User Defined Views From PostgreSQL using a Query? Like we can delete All functions using query : SELECT 'DROP FUNCTION ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ');' FROM pg_proc INNER JOIN pg_namespace ns ON (pg_proc.pronamespace = ns.oid) WHERE ns.nspname = 'my_messed_up_schema' order by proname; 回答1: Script for deleting all views in a certain schema: SELECT 'DROP VIEW ' || t.oid::regclass || ';' -- CASCADE? FROM pg_class t JOIN pg

How to create a table then commit then insert then commit and drop table?

好久不见. 提交于 2019-12-12 03:45:36
问题 Hi I am having a problem committing to a database. I am very new to Firebird SQL. But I have a query that creates a table, then commits it, then inserts it, commits it, view the data, drop the table and then commit it again. I am trying to do this dynamically where I can hit the execute button once and it just follows through. Is there a way to do that? This is the query. create table bp_customCollections( part_number varchar(255) ,part_description varchar(255) ,guided_reading_level varchar

sqsh SQL Server 2005 execute *.sql file

三世轮回 提交于 2019-12-12 02:42:10
问题 I would to drop remote SQL Server db via sqsh but, I don't know how does it works. I can connect to sql server with command: sqsh -Ulogin -Ppass -Smssql2005 回答1: Once you're connected to the server, you can drop a database with the command drop database [DBName] Assuming that there's no one connected to it, it should work. And if it doesn't, it'll tell you why. 回答2: echo 'USE table' > script.sqsh echo 'go' >> script.sqsh echo 'SELECT * FROM table' >> script.sqsh echo 'go' >> script.sqsh sqsh