how to query the database without accessing the tables, correct the database but not the tables
used is c# sql vs 08 sql server 2005 express
whenever and where ever an sql select statement is used, its always like
select * from tablename
or count statement is alsi like
select count something from table name
for selecting or doing anything on the tables,
i would like to know which tables exits in my the database i am connected to!
so like
select alltabl开发者_如何学Goenames from database_name.
please guide.
Personally, I would use the Information_Schema.Tables
& Information_Schema.Columns
views as these are views provided by Microsoft. (Rather than using the sysobjects tables)
to list all table of database
USE YourDBName
GO
SELECT *
FROM sys.Tables WHERE type='u'
to check table exists in database or not
IF EXISTS (SELECT 1
FROM sysobjects
WHERE xtype='u' AND name='tablename')
SELECT 'tablename exists.'
ELSE
SELECT 'tablename does not exist.'
The following query returns the names of the tables in an SQL Server database:
select name from sysobjects where xtype = 'U'
See http://database.ittoolbox.com/documents/finding-table-names-in-sql-18556 - simple queries for all table names and all columns for a given table.
or
EXEC sp_tables
精彩评论