andrew4582

SQL Sysobject scripts

Aug 15th, 2010
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.47 KB | None | 0 0
  1. --USE YOUR_DATABASE  
  2.  --GO
  3.  
  4.  -- Table and View Names
  5.  SELECT  name AS  TVNames FROM  sysobjects
  6.  WHERE (TYPE  =    OR  TYPE  =  )  
  7.  AND ( name NOT  LIKE    AND  name NOT  LIKE  )
  8.  ORDER  BY  name
  9.  
  10.  -- Table Names
  11.  SELECT  name AS  TNames FROM  sysobjects
  12.  WHERE  TYPE  =    AND  name NOT  LIKE    AND  name NOT  LIKE  
  13.  ORDER  BY  name
  14.  
  15.  -- View Names
  16.  SELECT  name AS  VNames FROM  sysobjects
  17.  WHERE  TYPE  =    AND  name NOT  LIKE    AND  name NOT  LIKE  
  18.  ORDER  BY  name
  19.  
  20.  -- Tables Count
  21.  SELECT  COUNT( name)  AS  TABLE_COUNT FROM  sysobjects
  22.  WHERE  TYPE  =    AND  name NOT  LIKE    AND  name NOT  LIKE  
  23.  
  24.  -- Views Count
  25.  SELECT  COUNT( name)  AS  VIEW_COUNT FROM  sysobjects
  26.  WHERE  TYPE  =    AND  name NOT  LIKE    AND  name NOT  LIKE  
  27.  
  28.  
  29.  GO
  30.  
  31.  -- Creates the table to hold the number of records per table in
  32.  IF   EXISTS (SELECT  *  FROM  sys.objects  WHERE  object_id  =  OBJECT_ID()  AND  TYPE  IN ())
  33.  DROP  TABLE  [TABLE_RECORDS]
  34.  ELSE
  35.  DELETE  FROM  [TABLE_RECORDS]
  36.  
  37.  GO
  38.  CREATE  TABLE  dbo. TABLE_RECORDS
  39.     (
  40.     TName nvarchar( 300)  NULL,
  41.     RecordsCount INT  NULL
  42.     )   ON  [PRIMARY]
  43.  GO
  44.  
  45.  
  46.  --Prints out the insert statements, use print to text feature
  47.  
  48.  SELECT (  +  name +  +  name +  )  AS  Name FROM  sysobjects
  49.  WHERE  TYPE  =    AND  name NOT  LIKE    AND  name <>  
  50.  ORDER  BY  name
  51.  
  52.  --Prints out the select count staments
  53.  SELECT (  +  name +    +  name)  AS  Name FROM  sysobjects
Advertisement
Add Comment
Please, Sign In to add comment