To see whether a column of a table is been used somewhere in the database [duplicate] - sql

This question already has answers here:
How can we figure out that a column in my oracle table is being populated/updated by a trigger of another table?
(3 answers)
Closed 5 years ago.
How to check whether a particular column of a table is used in any other object or not in Oracle? For example I have a table EMPLOYEE which has a column BONUS. I need to check whether this column of this table is been used by any other objects like View, Package etc in the database.

You can try the following SQL to check for the table and column used within the object definition
SELECT 1
FROM all_source
WHERE type IN ('PROCEDURE','PACKAGE BODY','FUNCTION')
AND text LIKE '%EMPLOYEE%'
AND text LIKE '%BONUS%';

Related

Can I locate tables based on a column value? [duplicate]

This question already has answers here:
Find a value anywhere in a database
(18 answers)
Closed 5 years ago.
I am working without documentation we have a dental system that displays the status of an appointment.
I have to report on who scheduled the appt. and who confirmed. The systems displays this as 'FIRM' and 'FIXED. I have located how they store the person who scheduled the appt. but not who has confirmed it.
But since they use 'FIRM" is there a way I can locate which tables have this value? we are running sql server 2008.
you can find out the table name which have column name like FIRM by using below query -
select * from information_schema.columns where column_name like '%FIRM%'
if you want to know where this column is referred (like in SP , trigger or view) or a or hard coded value is used to display, you can use below query-
select distinct object_name(id) from syscomments where text like '%FIRM%'

How do I search the name of a table, knowing only one of the table's column name in SQL? [duplicate]

This question already has answers here:
Search an Oracle database for tables with specific column names?
(4 answers)
Closed 7 years ago.
I'm trying to find a table containing a column that I know the name to. Is there some way to do a table search using only the name of the column?
In oracle
select * from user_tab_columns where column_name= '';

Get table definition in oracle sql plus [duplicate]

This question already has answers here:
How to get Oracle create table statement in SQL*Plus
(3 answers)
Closed 7 years ago.
I'm new to sql and I have created table using create table table_name.
And now I want to get this table definition or let's say source code, I know command desc table_name but that's not what I want. Could you help me figure it out?
Check the function: DBMS_METADATA.GET_DDL
http://psoug.org/reference/dbms_metadata.html

Displaying the name and data type of every column in a table [duplicate]

This question already has answers here:
How To Find Datatypes information in oracle schema?
(2 answers)
Closed 9 years ago.
I am working on a Database Management Systems assignment and have been unable to find a way to display the name and datatype of every column in a specific table. I don't know if this is needed but here is the link to the schema I am using for this assignment.
http://mym.cdn.laureate-media.com/2dett4d/Walden/ITEC/ITEC2060/documents/Schema.sql
The employee table is what I am trying to display from.
To list all columns for a specific table:
select column_name, data_type
from all_tab_columns
where table_name = 'EMPLOYEES';
More details in the manual: http://docs.oracle.com/cd/E11882_01/server.112/e25513/statviews_2103.htm#I1020277
If you are using SQL*Plus you can simply run
desc EMPLOYEES
instead.
Most other SQL clients have a similar feature.

How to change the length of a column in a SQL Server table via T-SQL [duplicate]

This question already has answers here:
What is the SQL to change the field length of a table column in SQL Server
(6 answers)
Closed 9 years ago.
I am looking to find out how to alter a fields properties contained in an SQL Server 2008 table via an SQL script.
I'm looking to change the 'Length' property specifically.
Does anybody know how to do this?
Thanks
So, let's say you have this table:
CREATE TABLE YourTable(Col1 VARCHAR(10))
And you want to change Col1 to VARCHAR(20). What you need to do is this:
ALTER TABLE YourTable
ALTER COLUMN Col1 VARCHAR(20)
That'll work without problems since the length of the column got bigger. If you wanted to change it to VARCHAR(5), then you'll first gonna need to make sure that there are not values with more chars on your column, otherwise that ALTER TABLE will fail.