Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Thursday, November 25, 2010

[SQL Server] Search Table using Column Name

In high pressure professional environment, we sometime require to know which tables have some xyz column, and its quite tedious to search entire database. Here is the magic-wand query for this problem:

SELECT * FROM sys.tables WHERE object_id IN
(SELECT object_id FROM sys.columns WHERE name LIKE '%<column-name>%')

Amazing... isn't it! :)

Wednesday, November 24, 2010

[T-SQL] Table Constraints

Table constraints define rules regarding the values allowed in columns and are the standard mechanism for enforcing data integrity.

Types of Constraints:
  1. NOT NULL enforces not to accept NULL values
  2. UNIQUE assures that the data is unique in the column (including one NULL).
  3. PRIMARY KEY uniquely identifies each record in the table without allowing NULL.
  4. FOREIGN KEY constraints the data to be inserted that is available in table's column it points to.
  5. CHECK is used to limit the value range that can be placed in that column.
  6. DEFAULT is used to insert a default value to all new records, if no value is specified.