Is it possible to rename a table in Firebird or I should create a new table and then move the data using insert?
Apparently not.
You must either create a new table, copying over old values or create a view with the intended name which is identical to the original table.
See http://www.firebirdfaq.org/faq363/ for further details.
It is possible to change the column name by:
ALTER TABLE "tableName" ALTER "columnName" TO "NewColumnName";
Related
HI I am generating schema script for a database, but when i finish creating it and and look at the script it gives create table statement for a table but not including all column in it also it generates alter table add column statement for the same tables but for missing columns which are left in create table statement.
see the attached screenshot.
Assuming the question is "why does it not create all of the columns in the CREATE TABLE statement" ...
You'll notice that between the CREATE TABLE and the ALTER statements, the value for SET ANSI_PADDING is altered. As the documentation notes, the setting's value is taken into account at the point in time when a column is created.
There's no way to override this setting in-line with the declaration of a column.
Since your table apparently contains a mixture of columns, some of which are defined with the setting ON and others with it defined OFF, there's no way to write a single CREATE TABLE statement that creates all of the columns in one go.
I created a empty table , I m unable to alter the Datatype of the field from web ui, is there any command line or Alter table command for Altering the datatype from INTEGER -> STRING
You need to recreate the schema, you cannot alter types.
If you want to copy the old data. Please make sure you create a temporary table, then once the schema is ready, you can query the old table and write to the new table making the transformation.
I have an existing DB2 database and a table named
employee with columns
id,e_name,e_mobile_no,e_dob,e_address.
How can I add a new column e_father_name before e_mobile_no?
You should try using the ADMIN_MOVE_TABLE procedure which allows to change the table structure.
The ALTER TABLE only allows adding columns to the end of the table. The reason is that it would change the physical structure of the table, i.e., each row would need to be adapted to the new format. This would be quite expensive.
Using the mentioned procedure ADMIN_MOVE_TABLE you would copy the entire table and during that process change the table structure. It requires a significant amount of space and time.
In DB2 IBM i v7r1 you can do it, try on your DB2 version
alter table yourtable
add column e_father_name varchar(10) before e_mobile_no
I always do the following --
Take a backup/dump of table data and db2look
(If you dump to a CSV file as I do I suggest dumping in the new format so for example put null for the new column in the right place.
Drop table and indexes
Create table with the new colunn
Load data with old values
Recreate all indexes and runstats.
Once you have done it a few times it becomes old hat.
in orther to get a column similar to the mysql ENUM type, I wrote a sql query as follows
ALTER TABLE [DbName].[dbo].[MediaContent]
ADD MediaType nvarchar(50)
check(MediaType in ('audio','video','song','other'))
this worked as wished(for test): But now I want to delete this column without success. It seems like there no way to directly delete a column which has a constraint up on it.
How can I solve this issue? I want to delete this column and create another one.
here is the error message I get while the deletion
The object 'CK__MediaCont__Media__14270015' is dependent on column 'MediaType'.
ALTER TABLE DROP COLUMN MediaType failed
because one or more objects access this
column. (Microsoft SQL Server, Error: 5074)
The object referenced in the error message is the name of the constraint. You should be able to use the follow:
ALTER TABLE [DbName].[dbo].[MediaContent]
DROP CONSTRAINT CK__MediaCont__Media__14270015
You need to first drop the check constraint mentioned in the error message since that's stopping you from dropping the column. Following that you may drop the column.
Drop the constrain first then drop the column ,it will work
This question already has answers here:
change the size of datatype in sql
(2 answers)
Closed 1 year ago.
I googled it enough but for some reason, mine doesnt work.
the column name is CD. type is VARCHAR2(10Byte)
Table name is TB_POT_ECD_CD
I want to change the size of column to VARCHAR2(100Byte)
ALTER TABLE TB_POT_ECD_CD MODIFY(CD VARCHAR2(100))
didn't work. Can anyone look at it?
It is perfectly possible to modify a column containing data, including changing its size; the one exception is that we cannot make a column smaller than the largest value existing in the column (1).
This is the syntax ...
alter table TB_POT_ECD_CD modify cd varchar2(100 byte)
/
... and here is a SQL fiddle too.
(1) This is true of 11gR2 and perhaps earlier versions; in older versions of Oracle we could only shrink empty columns. Thanks to #StanMcgeek for pointing this out to me.
"I get ORA-00942. Table or View does not exist."
That is a problem with your SQL. Probably you've misspelled the table, or you're trying to run the query from the wrong schema.
As you said on comments under your question you get ORA-00942 on ALTER TABLE query. There are few solutions I can think of:
Try to specify the owner/schema in the query
You have somehow corrupted entry in statement cache: try this query ALTER SYSTEM FLUSH SHARED_POOL; and then your ALTER TABLE with MODIFY again
Check wether your table is an actual table, not, for example, a synonym to a table in a different schema
You may remove that column and add it again with new size
ALTER TABLE TB_POT_ECD_CD
DROP COLUMN CD
ALTER TABLE TB_POT_ECD_CD
ADD CD VARCHAR2(100)