Oracle SQL: rename object attribute - sql

Looking at the documentation for the ALTER TYPE statement, there seems to be no possibility to change the name, only the type. Is there any possibility to rename an attribute of an SQL object?
My first thought would be to first create an attribute with the new name, copy the data, and then drop the old attribute, but I hope there is a better solution, something like alter type my_type rename attribute abc to xyz.

I believe you can use CREATE OR REPLACE TYPE [type_name]

Related

add column to existing table postgres

I have a table1 created in the prod environment. I have to add column to an existing table1.
Im using the function create of replace to create the table with the suitable ddl.
To add the column shall i add it manually on the prod machine and change the ddl.
Or changing only the ddl will do it?
Thank you
As far as i know there is no such thing as a create or replace table syntax. that should only work for functions or views.
Use the ALTER TABLE Table1 ADD NewColumn {DATA_TYPE} command.
The way you phrased your question makes me think you use a 3rd party database version control like liquibase. If that is the case leave the initial create DDL alone and just add it as a separate change. If you change the initial ddl it will only affect new databases.

Cannot find data type user defined data type

I am getting Column, parameter, or variable #1: Cannot find data type dbo.SUBSYSTEM_CODE. error on user datatype.
CREATE TABLE #PREDEFINED_SUBSYSTEMS
(
SUBSYSTEM_CODE dbo.SUBSYSTEM_CODE PRIMARY KEY
);
After I checked user defined datatype I can see. I am using SQL 2012 and also I applied set compatibility_level = 110 on datatype still didn't work.
What other alternatives I have to fix this?
Probably you need to define type inside tempdb:
USE tempdb;
GO
CREATE TYPE dbo.SUBSYSTEM_CODE ...
Our problem was with schema
we moved table type from dbo to hub schema, and after that we got this error,
you need to use schema before table name for it to work
and dont forget about dynamic sqls which you might have

How do I Alter an attribute to change its datatype in Object type?

How do I Alter an attribute to change its datatype in an Object type?
You're looking for the ALTER TYPE statement, and specifically for the alter attribute definition clause. For example, to change the type of an attribute to NUMBER from something else you'd use
ALTER TYPE MY_TYPE
MODIFY ATTRIBUTE SOME_ATTRIBUTE NUMBER;
Share and enjoy.

change attributes data type in database table when it is already filled with records

Could we change attribute's data type when the database table has record in SQL?
I am using Microsoft Management Studio 2008. The error that i am getting is:
** Error converting data type nvarchar to float. **
In short: It is possible with alter column command ONLY if the altered data type is compatible with newly modified one. In addition, it is recommended to be done with transaction.
For example: You may change a column from a varchar(50) to a nvarchar(200), with a script below.
alter table TableName
alter column ColumnName nvarchar(200)
Edit: Regarding your posted error while altering column type.
** Error converting data type nvarchar to float. **
One way would be to create a new column, and convert all good (convertible and compatible) records to new column. After that you may wanna to clean-up the bad records that do not convert, delete old column and re-name your newly added and populated column back to the original name. Important: use testing environment for all this manipulations first. Usually, playing with productions tables turns to be a bad practice to screw things up.
References to look for more discussions on similar SE posts:
Change column types in a huge table
How to change column datatype in SQL Server database without losing data
Obviously, there is no default conversion to your new datatype. One solution could be to create a second column with the requested type, and write your own conversion function. Once this done, delete the first column and rename the second one with the same name.
Things to consider: How big your table is. You then use the alter table syntax. We do not know what data type you want to change, so just for e.g.
alter column:
Alter Table [yourTable] Alter column [yourColumn] varchar(15)
You could also try to add a new column and then update that column using your old column. Drop the old column. Rename the new column. This is a safe better way, becasue at times the data that you hold might not react well to the new data type...
A post to look into for ideas: Change column types in a huge table, How to change column datatype in SQL database without losing data
Alter datatype of that column ..But In general sql wont allow to channge.It will prompt u drop that column..There is setting to achive that thing.
Go to Tool->Option->designers->Table and Database designers and Uncheck Prevent saving option.I m taking abt sql server 2008R2.Now u can easily alter data type.

Is it possible to rename a table in Firebird?

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";