SQL SERVER – 2005 List All Tables of Database

This is very simple and can be achieved using system table sys.tables.

USE YourDBName
GO

SELECT
*
FROM sys.Tables
GO

This will return all the tables in the database which user have created.

Reference : Pinal Dave (https://blog.sqlauthority.com) , BOL

SQL Scripts, SQL System Table
Previous Post
SQL SERVER – Explanation and Example Four Part Name
Next Post
SQL SERVER – Running Batch File Using T-SQL – xp_cmdshell bat file

Related Posts

448 Comments. Leave new

  • I WANT TO SEE ONLY USER CREATED DATABASE NAMES.HOW CAN I DO .PLEASE HELP

    Reply
  • how to know memory of each table and database…?

    Reply
  • Hi Pinal ,

    I am very thankful and I am appreciate your effort by helping us.
    I have this case; I need to modify certain data in a certain column for all tables contain that value, for example let’s say that we have DB named “DB_Name” with the following tables:
    Table “X” & Table “Y”, each one of these tables has a column name “id” where it’s a primary key in table “X” and foreign key in tables “Y”.
    I f I tried to change the data in the table “Y” I get this message [The update statement conflicted with the REFERENCE constrains “FK_Y_ REFERENCE_X” the conflict occurred in database “DB_Name”, table “dbo.X”]
    So I go to the table “X” and trying to change the data but I get the same message, what I need is to break the relation in between these tables to make the changes then restore the relation again.
    Note: I have almost 350 tables in the DB that I work with and they are all related to each other.
    Many thanks in advance :)

    Reply
  • how to find unused stored procedures?

    Reply
  • Hi guys,
    I created a view in sql2008 and when I try to select data using the view I got an error saying “Invalid object name” in my select statement for the fields. I used dbo as the schema name in defining the view.
    Any help will be highly appreciated.

    Thanks,
    Tony

    Reply
  • Hi
    We need to list all views from each databases in sql server. Can you help me this out?
    Thanks

    Reply
    • One option is

      EXEC sp_msforeachdb ‘select table_name,”?” as db_name from [?].information_schema.tables where table_type=”VIEW”’

      But you can simulate the same by following this blog post

      Reply
  • Hi evryone,
    I am trying to create an advance search query from multiple optional parameters. Could anyone tell me the best way to do this. I have 8 parameters to work with.

    Thanks,

    Reply
    • Try this logic

      where
      (col1=@param1 or @param1 is null)
      and
      (col2=@param2 or @param2 is null)
      .
      .
      .

      Reply
  • Thanks very much Madhivanan!!
    I started out with this approach but I find myself doing a lot if else statement that end up not given me the correct results. I have to come up with every possible combination for the 8 parameters. Is there a more efficient way to come up with every possible combination that the user can search by,.

    Thanks!
    Tony

    Reply
  • Thanks Madhivanan for your assistance, I will apply the logic…

    Reply
  • Thanks for the info !

    Reply
  • HI
    I need to check the my SQL server version ( 2000 or 2005)how to check the SQL server version and I need the document SQL server upgarde 2008 64 bit.can you send me document .

    Reply
  • How I can truncate all tables except the master tables..
    Do You have any script where I just pass the master tables tuncate all tables except passed (master tables) ?

    Thanks & Regards
    Raman verma

    Reply
    • Follow the script showed in this blog. You can include master tables in the WHERE caluse so that they wont be truncated

      Reply
  • Hi, I need to retrieve my database tables so that I can copy them into word document for my project submission. Im using SQL SERVER 2005.

    Reply
    • Do you want copy the table names or structure of the tables?

      If tables names

      Select table_name from information_schema.tables

      It structures, make use of [b]Generate Script option[/b] from Management studio

      Reply
  • How to get list of connected users to particular DB

    Reply
  • Good evening sir,

    i have one table Users and the fields are

    UserID Bigint,
    UserName nvarchar(50),
    SponsorID Bigint

    this question is related to Level tree in which i have to find out the parent of any user recursively.

    in this scenario when a new member is registered, he must have to enter his SponsorID (who is sponsoring the User). after that i have to find out the sponsors of all parent till the root node comes.

    the UserID may be a SponsorID for other user.

    so how can i recursively find the the userID and SponsorID of all the users with the help of Cursor.

    please sir help me out from this.

    thanking you,

    Reply
  • Hi,

    How to list of users connected to a particular database in sqlserver 2005?

    koteswarrao

    Reply
  • Hey Pinal,
    I am trying to get a list of all the database names along with their tables for SQL 2000, SQL 2005 and SQl 2008.
    sysobjects only gives the table names
    while information_schema.tables does not work in SQL 2000 Enterprise Edition.
    Please help.

    Lisa

    Reply
    • Here is a quick way to do it

      exec sp_msforeachdb ‘select ”?”,* from information_schema.tables’

      But I recommend to follow this post

      Reply
  • Krishna Chaudhary
    July 16, 2010 5:54 pm

    Hi,

    how can i delete the logs of the database. because my database logs size is 54 GB so not being srink.

    now what should i do??

    Reply
  • thomasknudson
    July 18, 2010 3:49 am

    Answered my question right away, thanks!

    Reply
  • How do i sources for information from more than two tables. i mean combining more than two tables

    Reply
    • Hint

      select columns from
      (
      select columns from table1
      union all
      select columns from table2
      ) as t
      where

      Reply

Leave a Reply