Thursday 4 April 2013

Important Sql Queries

Q 1: How to get columns of a table in Sql Server?

Ans :  There are many ways to do this
  1. EXEC sp_columns 'tbFeeStructure',null,null,null,0
  2. SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('dbo.yourTableName')
  3. sp_help yourTableName
  4. SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='YourTableName'
All above queries are used to get columns of the given table.

Q 2:  How to columns data type and NULL to NOT NULL (or NOT NULL to NULL)?

Ans:ALTER TABLE YourTableName ALTER COLUMN Column_Name DataType NOT NULL


No comments: