Showing posts with label sys.columns. Show all posts
Showing posts with label sys.columns. Show all posts

Wednesday, January 27, 2016

Find everything about objects and columns in SQL Server 2012

In SQL Server 2012, sys.columns is a view you can find in the node System Views in the msdb database.

The various columns in sys.views are shown in this next image. You can find everything about the Columns in this view.



If you know the ObjectID of the Column of a table in the database, you can find its name from this query, the intellisense gives you an idea of this selection.

SysColumnName.png

A typical query and its output are as shown for finding the column name from ObjectID.

SysColumnName_02.png

If you know the Column_Name then you can find Column_ID, the intellisense gives you an idea of this selection.

SysColumnID.png

A typical query and its output are as shown for finding Column ID from Column Name.

SysColumnID_02.png

Starting from table name you can get the columns from these queries:

You can also get the ObjectID of the table from this query:

Use Northwind
go
Select *
From sys.tables
where tables.name='Employees'

go

The above query returns one value=245575913
Using the above you can get a whole lot of information for the columns from this query:

Select *
from sys.columns
where Columns.object_id=245575913












Tuesday, January 26, 2016

Finding Collation used by the SQL Server objects

Collation is locale specific and you choose while installing the SQL Server. Sorting depends on this as well as case sensitiveness.


Collation.jpg


You can also search to find what kind of collation is supported on your server using the following query for the whole database (this example is for the master database)
Select name, COLLATION_NAME from sys.databases where name=N'master';
Response: SQL_Latin1_General_CP1_CI_AS master
If you have a column that is of varchar data type (something textual) you use this query for the column,
SELECT name, collation_name FROM sys.columns WHERE name = N'optname';
Response: optname SQL_Latin1_General_CP1_CI_AS

Note that there is a column called optname in the master database
You can find all the collations that are supported using this query:


CollationsSQLServer2012.jpg

When Identity Security Becomes a Wall — Not a Shield

After a breach that forced a reset of my digital identity, I hit a roadblock I never anticipated: multi-factor authentication (2FA) locked m...