Monthly Archives: December 2007

Get Table Schema from MS SQL

You can get table schema or columns of table from query using system object.
Try this
select * from information_schema.tables
select * from information_schema.columns where column_name = ‘StudentID’
select substring(o.name,1,50) as “Table Name”,
c.colid,
substring(c.name,1,30) as “Column Name”,
substring(t.name,1,30) as “DataType”,
c.length
from sysobjects o
left join syscolumns c on (o.id=c.id)
left join systypes t on (c.xusertype=t.xusertype)
where substring(o.name,1,250) like ‘%tblStudentMaster%’
order by 1 ASC
See order by here, [...]

SQL Server Transact-SQL General Tips

from SQL-Server-Performance.com
SQL Server Transact-SQL General Tips

By : Brad McGehee
 

Don’t include code, variable, or parameters that don’t do anything. This may sound obvious, but I have seen this in some off-the-shelf SQL Server-based applications. For example, you may see code like this:
SELECT column_name FROM table_name
WHERE 1 = 0
When this [...]