alter

MySQL ALTER TABLE on very large table - is it safe to run it?

孤街醉人 提交于 2020-01-03 07:21:08
问题 I have a MySQL database with a MyISAM table with 4 million rows. I update this table about once a week with about 2000 new rows. After updating, I then alter the table like this: ALTER TABLE x ORDER BY PK DESC I order the table by the primary key field in descending order. This has not given me any problems on my development machine (Windows with 3GB memory). Three times I have tried it successfully on the production Linux server (with 512MB RAM - and achieving the resulted sorted table in

Create table with COUNT ms-access

自闭症网瘾萝莉.ら 提交于 2019-12-31 05:13:09
问题 I have a database and I want to create a table with COUNT function in it. Is it possible ? I have 3 existing tables: Member Feedback Attendance In Feedback table, 2 columns Class_ID, Likes (Class_ID link with the attendance, as each member attend 1 class eg. class 1,2,3,etc. and Likes is for the number of people like the class). In Attendance table, 3 columns: Class_ID Member_ID Non_member_name Now I want to alter Feedback table to add 2 new columns. One to count the number of people attend

How to delete records from a column which belong to a different data type?

假装没事ソ 提交于 2019-12-25 08:30:36
问题 So I inserted few records in a table manually (without using Stored procedure) and rows were fine under a column " COLMN ". Then I tried to automate it by using dynamic-SQL in stored procedure. Unfortunately I ended up appending rubbish records (entered float in a column which was meant to be Char). How can I delete these selected rubbish records which don't belong? Here is how my table looks like: ...And I want to delete those numeric records (from column " COLMN ") I planned to achieve this

How to create/add columns using a variable in a loop

人走茶凉 提交于 2019-12-24 16:32:52
问题 I am very new to SQL in that I just finished reading Sams Teach Yourself SQL in 10 Minutes and that is my only SQL knowledge. So now that I'm done with the book, I'm trying to create some tables so I can play around with them. I can easily create a table with a known amount of columns and specified header. Where I am having trouble is creating a table with an unknown amount of columns and a date as the header. What I have tried so far is this: DECLARE @start_date AS DATE DECLARE @end_date AS

Alter table, add column / ORA-00984: column not allowed here PLSQL

梦想与她 提交于 2019-12-24 07:58:26
问题 The next statement SQL give me a "ORA-00984: column not allowed here": ALTER TABLE USUVCB.TVCB_RUT_SII ADD (Fecha_Inicio VARCHAR2(10 BYTE) DEFAULT TO_CHAR(SYSDATE, "YYYY-MM-DD") NOT NULL); It's into a PL-SQL, like this: SET SERVEROUTPUT ON DECLARE Fecha VARCHAR2(8) := TO_CHAR (SYSDATE, 'YYYYMMDD'); Tabla VARCHAR2(28) := 'USER.TABLE_' || Fecha; BEGIN SAVEPOINT START; BEGIN EXECUTE IMMEDIATE 'CREATE TABLE ' || Tabla || ' AS SELECT FIELD_1, FIELD_2, FIELD_3 FROM USER.TABLE'; EXCEPTION WHEN

How to loop through different schemas and execute some sql on each?

ε祈祈猫儿з 提交于 2019-12-23 18:35:35
问题 I have a case where I have 70 oracle schemas and I have to execute the same script on each which would be the best way to achieve this. Is it possible with a CURSOR? For now I'm doing it with ALTER SESSION SET current_schema = SCHEMA_1; ==== ALTER SESSION SET current_schema = SCHEMA_2; ==== ALTER SESSION SET current_schema = SCHEMA_3; ==== And I replace the "====" with my script, I+m doing it with Notepad++ but I have to prepare the script manually and if the script is long I have to split it

MYSQL 5.5 Drop Primary Key

做~自己de王妃 提交于 2019-12-23 13:13:54
问题 I am upgrading my quartz.net version from 1.0.3 to 2.0.2 There is a migration script for database schema, which was was written for MSSQL, and I am trying to write a MYSQL version of it. However, I haven't been able to drop primary keys (which I need to). Original MSSQL version of script: ALTER TABLE BLOB_TRIGGERS DROP CONSTRAINT BLOB_TRIGGERS_PKEY; ALTER TABLE BLOB_TRIGGERS DROP CONSTRAINT BLOB_TRIGGERS_TRIGGER_NAME_FKEY; ALTER TABLE SIMPLE_TRIGGERS DROP CONSTRAINT PK_SIMPLE_TRIGGERS; ALTER

How do you assign a column default in MySQL to another column's value?

a 夏天 提交于 2019-12-23 09:42:06
问题 I want to add a new column to a table in MySQL database that should get the value of another column in the same table. Is this possible? If so, how do you do it? 回答1: Starting with MySQL 5.0.2 you can write a stored procedure linked to a TRIGGER which can examine the new column each time a row is inserted, and automatically copy the other column's value into the new column if no value was supplied for the new column. 回答2: As of 20101212 mysql does not support defaulting 2 timestamp columns,

ALTER TABLE ADD COLUMN takes a long time

核能气质少年 提交于 2019-12-17 15:03:42
问题 I was just trying to add a column called "location" to a table (main_table) in a database. The command I run was ALTER TABLE main_table ADD COLUMN location varchar (256); The main_table contains > 2,000,000 rows. It keeps running for more than 2 hours and still not completed. I tried to use mytop to monitor the activity of this database to make sure that the query is not locked by other querying process, but it seems not. Is it supposed to take that long time? Actually, I just rebooted the

How do I alter a mysql table column defaults?

こ雲淡風輕ζ 提交于 2019-12-17 10:57:12
问题 I have a table with a column of type timestamp which defaults current_timestamp and updates to current_timestamp on every update. I want to remove the "on update" feature on this column. How do I write the alter statement? I tried the following: ALTER TABLE mytable alter column time set DEFAULT now(); but this didn't work. 回答1: Pete was almost correct but used the wrong syntax for 'change': ALTER TABLE mytable CHANGE `time` `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP Notice that you