Important alert: (current site time 7/15/2013 7:47:11 PM EDT)
 

VB icon

All Tables and Columns

Email
Submitted on: 7/28/2003 5:06:27 PM
By: marisol gonzalez 
Level: Advanced
User Rating: By 4 Users
Compatibility: SQL Server 2000, SQL Server 7.0
Views: 22928
 
     Store Procedure that display all tables and columns, type, length for any database.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
--**************************************
-- for :All Tables and Columns
--**************************************
none.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
--**************************************
-- Name: All Tables and Columns
-- Description:Store Procedure that display all tables and columns, type, length for any database.
-- By: marisol gonzalez
--
-- Inputs:all optionals, but the order is
'c', <col name> or
't', <table name>
<col name> or <table name> could be full or partial.
--
-- Returns:returns grid.
--
-- Assumes:you must create this sp at master database.
example of use:
with query analyzer at any database, execute the procedure with no parameters, the result is all tables, col´s and types for current database.
--
--This code is copyrighted and has-- limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=730&lngWId=5--for details.--**************************************

--despliega todas las columnas y tablas en la base de datos 
--parametros:ninguno (por defecto) 
--Opcionales:
--'c'-->ordenado por columnas, 'nombre de col'
--'t' --> ordenado por tabla, 'nombre de tabla'
--mgJulio 24,2003
CREATE PROC sp_columnasytablas
@orden char(1) = null ,
@objeto varchar(255) = null
AS
SET NOCOUNT ON
if ( (@orden is null ) or ( (lower(@orden) <> 'c' ) and (lower(@orden) <> 't' )))
print 'Opciones: c ó nada--> ordenado por columna, t --> ordenado por tabla'
--Búsqueda por defecto---
if(@orden is null )
 goto BuscarPorDefecto
--Búsqueda por columna y nombre de la columna---
if((lower(@orden) = 'c' ) and (@objeto is not null))
 begin
goto BuscarPorColumnaYNombre
 end
--Búsqueda solo por columna ---
else
begin
if(lower(@orden) = 'c' ) 
 goto BuscarSoloPorColumna
end
--Búsqueda por tabla y nombre de la tabla---
if((lower(@orden) = 't' ) and (@objeto is not null))
begin 
goto BuscarPorTablaYNombre
end
--Búsqueda solo por tabla ---
else
 begin
 if(lower(@orden) = 't' )
goto BuscarSoloPorTabla
end
--------------------//-------------------------------
BuscarPorDefecto:
--select 'Por Def'
	select sc.name as 'columna' , so.name as 'tabla', 
st.name as 'tipo', sc.length as 'largo',
 sc.xprec as 'prec', sc.xscale as 'escala'
	from syscolumns sc, sysobjects so, systypes st
	where so.xtype = 'U' and 
	 sc.id = so.id and
 sc.xtype = st.xtype
	order by sc.name, so.name
return
BuscarSoloPorColumna:
--select 'Solo Col'
	select sc.name as 'columna' , so.name as 'tabla', 
st.name as 'tipo', sc.length as 'largo',
 sc.xprec as 'prec', sc.xscale as 'escala'
	from syscolumns sc, sysobjects so, systypes st
	where so.xtype = 'U' and 
	 sc.id = so.id and
 sc.xtype = st.xtype
order by sc.name
return
BuscarPorColumnaYNombre:
--select 'Col y Nom'
	select sc.name as 'columna' , so.name as 'tabla', 
st.name as 'tipo', sc.length as 'largo',
 sc.xprec as 'prec', sc.xscale as 'escala'
	from syscolumns sc, sysobjects so, systypes st
	where so.xtype = 'U' and 
	 sc.id = so.id and
-- sc.name = @objeto and 
 sc.name like @objeto + '%' and 
 sc.xtype = st.xtype
order by sc.name
return
BuscarPorTablaYNombre:
	select so.name as 'tabla', sc.name as 'columna' , 
st.name as 'tipo', sc.length as 'largo',
 sc.xprec as 'prec', sc.xscale as 'escala'
	from syscolumns sc, sysobjects so, systypes st
	where so.xtype = 'U' and 
	 sc.id = so.id and
-- so.name = @objeto and 
 so.name like @objeto + '%' and 
 sc.xtype = st.xtype
order by so.name
return
BuscarSoloPorTabla:
	select so.name as 'tabla', sc.name as 'columna' , 
st.name as 'tipo', sc.length as 'largo',
 sc.xprec as 'prec', sc.xscale as 'escala'
	from syscolumns sc, sysobjects so, systypes st
	where so.xtype = 'U' and 
	 sc.id = so.id and
 sc.xtype = st.xtype
order by so.name
return


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/30/2003 2:06:32 PMmozka

por que debe de ser compilado en la master ??? si es asi este procedimiento solo regresara lo que existe en esa base de datos y no en las demas, a menos que lo marques como objeto de sistema, otra cosa es que no te diferencia los tipos de datos ya que un varchar tiene longitud y un numerico no y no lo veo como avanzado si no mas bien como promedio, 3 globos de mi parte
(If this comment was disrespectful, please report it.)

 
6/3/2005 12:01:52 AM

this a good source code
have any sorce code more??

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.