Jumat, 28 Februari 2014

Xathrya Sabertooth

Xathrya Sabertooth


List All Constraints of Database or Table in SQL Server

Posted: 27 Feb 2014 04:23 PM PST

A constraint is defined as a specific rule applied to data in a table in such a way when the constraint is violated, the action is aborted. Constraint can be specified when the table is created (inside the CREATE TABLE statement) or after the table is created (inside the ALTER TABLE statement).

Many times when we use action like: INSERT, UPDATE, DELETE, we get error(s) because on or the other constraint is violated. It’s getting annoying when we are new to this database and don’t know what constraints are set on the tables.

In this article, we will discuss about how to list all the constraints in a database. All the methods given have been tested on SQL Server 2012.

Method 1: Using sys.objects

sys.objects is a special table which contains row for each user-defined, schema-scoped object that is created within a database. Including our constraint.

All we need to do is query that table.

-- To Display all the Constraints in the Database  SELECT *  FROM [sys].[objects]  WHERE [type_desc] LIKE '%CONSTRAINT'

The above query will display all the fields of sys.objects. For convenience use, we can refine it to display in elegant way.

-- To Display all the Constraints in the Database  SELECT OBJECT_NAME(object_id) AS [ConstraintName],         SCHEMA_NAME(schema_id) AS [SchemaName],         OBJECT_NAME(parent_object_id) AS [TableName],         [type_desc] AS [ConstraintType]  FROM [sys].[objects]  WHERE [type_desc] LIKE '%CONSTRAINT'

We can also display all the constraints of a table, let say ‘NEST_User’, by querying:

-- To Display all the Constraints in table 'Nest_User'  SELECT OBJECT_NAME(object_id) AS [ConstraintName],         SCHEMA_NAME(schema_id) AS [SchemaName],         [type_desc] AS [ConstraintType]  FROM [sys].[objects]  WHERE [type_desc] LIKE '%CONSTRAINT' AND OBJECT_NAME(parent_object_id)='NEST_User'

Method 2: Using INFORMATION_SCHEMA.TABLE_CONSTRAINTS

information schema view is one of several methods SQL Server provides for obtaining metadata. It provides an internal, system table-independent view of the SQL Server metadata. However, it has one shortcoming; it won’t display the default constraints of the database.

– To Display all the Constraints in the Database    SELECT *   FROM [INFORMATION_SCHEMA].[TABLE_CONSTRAINTS]    – To Display all the Constraints in table 'NEST_User'  SELECT *   FROM [INFORMATION_SCHEMA].[TABLE_CONSTRAINTS]  WHERE [TABLE_NAME]='NEST_User'

To display DEFAULT constraint in the database we can use following SQL statement.

– To Display Default Constraints in Database    SELECT OBJECT_NAME(PARENT_OBJECT_ID) AS [TABLE_NAME],         [COL_NAME] (PARENT_OBJECT_ID, PARENT_COLUMN_ID) AS [COLUMN_NAME],         [NAME] AS [DEFAULT_CONSTRAINT_NAME]  FROM [SYS].[DEFAULT_CONSTRAINTS]

Kamis, 13 Februari 2014

Xathrya Sabertooth

Xathrya Sabertooth


Desktop Experience for Windows Server 2012

Posted: 13 Feb 2014 01:19 AM PST

Windows Server 2012 and Windows 8 are like twins. They have the same core technology but then differs in advance utilization. Windows Server is used for server purpose, however we can still experience Windows 8 on Windows Server 2012. The thing we need to know is Desktop Experience, a feature added by Microsoft for doing so.

In this article we will install additional desktop applications and add several GUI improvements.

After installation, we will have following effects:

  • Application added to the Start Screen:
    • Windows Store
    • Default Programs
    • Windows Media Player
    • Character Map
    • Disk Cleanup
    • Snipping Tool
    • Sound Recorder
    • Math Input Panel
  • Start screen will automatically appear instead of the classic desktop
  • Charms bar (bar on the right side of the screen) with buttons ‘Search’, ‘Start’, ‘Settings’, ‘Share’, and ‘Device’
  • The Settings option of the Charms bar will also have the 'Change PC Settings' option which is a Windows 8 version of the Control Panel.
  • The context menu of the classic desktop will have the 'Personalize' option added.
  • Applications: Windows Mail, Windows Photo Viewer
  • Services: ActiveX Installer, Offline Files, Windows Image Acquisition (WIA), System Events Broker, Time Broker, WebClient, Still Image Acquisition Events, Microsoft Account Sign-in Assistant
  • Miscelanous: Various screensavers, Ability to burn .iso's from Windows Explorer, Sync Center in Control Panel, Adobe Flash Player

Steps

Open “Server Manager” and make sure you are on “Dasboard” tab. Click on “Add roles and features”

install-ad-1

Skip the information page by clicking “Next”

Select “Role-based or feature-based installation” as installation type and then click “Next”

install-ad-2

We want to install Desktop Experience feature on local server which is also selected by default so choose “Next”

install-ad-3

Desktop Experience is not a Role so click “Next” to bring ourselves to “Features” page.

Here expand “User Interfaces and Infrastructure” and check the “Desktop Experience”. You will be asked for installation of features required by Desktop Experience so just agreed with it.

desktop-exp

desktop-exp2

At the confirmation page, optionally check the “Restart the destination server automatically if required” checkbox as the Desktop Experience feature will need a restart to complete. You can also manually restart the server after the wizard completed.

desktop-exp3

Once your machine restarted (either you choose automatically or restart it manually) you will see your desktop now has more applications.