Constraints in SQL


Definition of Constraint

It is the set of restrictions for data while storing and retrieving from DB and maintains the Data Integrity. I.e. It ensures the consistency and correctness of data stored in the database.

Constraint Categories
  • Entity Integrity – Unique, Primary key
  • Domain Integrity – Not null, Check
  • Referential Integrity – Foreign key
Principle of Constraints
  •  Can create constraints to ensure data integrity.
  •  Constraints define routed that must be followed to maintain consistency and correctness of data
Enforcement of Constraints - Constraints can be enforced in two levels
  • Column Level
  • Table Level
Constraints construction - Constraints can be created either by using the following statements,
  • Create Table
  • Alter Table
Syntax: - Using CREATE

CREATE TABLE table name (column name CONSTRAINT constraint_name Constraint_type[Cons_name, Cons_type].

Syntax: - Using ALTER

ALTER TABLE table name ADD CONSTRAINT constraint name constraint type (condtion)

With Check /with no Check  - Specifies whether the existing data has to be check or not to check for a newly added constraint or a renamed constraint.

1.       Entity Integrity Constraint

This Constraint ensures that each row can be uniquely identified by an attribute known as Primary key or Unique Key.

                    I.            PRIMARY KEY (Not Null + Unique)

·         A Primary key  constraint is define on a column or a set of columns to create identity rows in a table
·         Primary key column can’t contain null values, since it is used to uniquely identify rows in a table.
·         If a primary key constraint is defined on a column that already contains data then existing data in the column is checked for any duplicate values. If any duplicates found then the primary constraint will be rejected.

Syntax:
CONSTRAINT constraint name PRIMARY KEY (column name 1, column name 2..)

Example 1:
CREATE TABLE Emp (Eid Char(4) CONSTRAINT Eid_PK PRIMARY KEY)

Example 2:
ALTER TABLE Emp ADD CONSTRAINT Eid_PK PRIMARY KEY(Eid).

                  II.            UNIQUE

·         UNIQUE is used to enforce to apply uniqueness on non Primary key columns
·         It allows NULL Values
·         Multiple unique constraints can be created on a table.

Syntax:
CONSTRAINT constraint name UNIQUE (column name 1, column name 2..)

Example 1:
CREATE TABLE Emp SSN Char(25) CONSTRAINT cons_SSN UNIQUE

Example 2:
CREATE Table Emp(Empid numeric(5),Email Varchar(25)) Constraint Email_uk UNIQUE(Email))

2.       Domain Integrity Constraint

This Constraint ensures that only range of values to be stored in a column and It enforces by restricting the type of data, range of values, and format of the data.

                    I.            NOT NULL

Ensures the column contains no NULL values, by default the table can contains NULL values and it can be able to specified only at the column level not at the table level.

Example
CREATE TABLE Emp ( Eid no(6),Last Name Varchar (25) NOT NULL, Salary no(8,2), PRIMARY  KEY(Eid))


                  II.            CHECK

·         CHECK constraint enforces domain integrity by restricting the values inserted in a column.
·         It is possible to define a multiple CHECK constraints on a single column.
·         A single CHECK constraint can be applied to multiple columns when it is defined at the table level.

Syntax:
CONSTRAINT constraint name CHECK (expression)

Example:
CREATE TABLE Emp (salary numeric (8,2,) CONSTRAINT sal_CK CHECK(Salary > 1500))

3.       Referential  Integrity (RI)

It ensures that the values of the foreign key matches with the values of the corresponding primary key

                    I.            Foreign Key

The key is used to remove the inconsistency in two tables when data in the one table depends on the data in the another table

Syntax:
CONSTRAINT constraint name Foreign Key (column name) REFERENCE table name (column name)

Example:
CREATE TABLE Emp (Eid numeric(8,2), Did numeric(8,2) CONSTRAINT Did_fk REFERENCE Dept(Did))

                  II.            DEFAULT

Default constraint can be used to assign a constant value to a column and there is no need for user input for a specified column

Syntax:
CONSTRAINT constraint name DEFAULT (constant expression/NULL)

Example:
CREATE TABLE Emp (City Char(15) DEFAULT ‘New York’)
                                                                                                                                 
                                                                                                                       

How to Enable and Disable the Task Manager


As a part of the administrative task enabling and disabling the task manager is essential as per their own organizations policy the action prevents the end users from opening Task Manager (Taskmgr.exe). If the setting is in action and the user is trying to access the Task Manger, a message appears explaining that a policy prevents the action.
Let’s see how to disable and enable the task manager by group policy editor and registry combination. The portion is so expedient when the Task manager is accidentally disabled.

[Method: 1] Group Policy Editor

  • Click on Run -->; gpedit.msc




  • The Group policy Windows opens, in the Local Computer Policy, Choose the User configuration -->Administrative Templates --> ;System -->Ctrl +Alt+ Del Options  on the right pane click on the Remove Task manger setting as shown in the following fig,

  •              The Following dialog opens, From this  you can enable or Disable the task manager,
Enable – Task Manager removed from your sys.
Disable – Enabling task manager.


  •             Similarly you can able to easily remove the Lock Computer, Change Password, and Logoff from the system from Ctrl +Alt+ Del Options.

[Method: 2] Registry Edit

Another Way of enable/disable can be done by editing the registry using regedit Command, Navigate to the following structures and make the following changes,

Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\Windows\CurrentVersion\Policies\System
Name: DisableTaskMgr
Type: REG_DWORD
Value: 1= Disable’s the task manager
Value: 0= Enables the task Manger

Note: Requires Administrator rights to do the task.




Web Application Security in .Net



Introduction to Application Security

Security threat is the most serious issue experienced by all not in application but also in all space, how a house without proper security amenities will possess security threat from the foreign objects similar to that web applications are also possess the vulnerable attacks by the unintended users, Because of this critical part the intended users of the web application faces the loss of their privacy, integrity sometimes their resources also.

What is Application Security?
Application security is a mechanism, Practices & procedures to safeguard the resources of the application, ensure the proper privacy of the users and their information̢۪s, proper privileges & rights management.

Application security principles

1.       Principle of least privileges to be adopted: - To avoid and limit the impending damage processing of script or the execution of code should be routed via least privileged account.
2.       Practice the defense mechanism should be in depth: - Place the check point in each & every layer of the application and validate the credentials and authorize the users to access the next levels.
3.       Do not trust on user input: - Validate the all user inputs before computing any operations and preventive measure to be taken.   
4.       Practice secure defaults: - Employ common security standards to application to reduce the settings of security.
5.       Validate input at the gate: - Authenticate the user at the entry level of the application will minimize the security risks.
6.       Fail to a secure mode: – inform the user by limited error message if application fails and do not leave valuable data unprotected. 

Types of Common web application attacks
 
There are several attacks which are frequently exploited by hackers and some common attacks are,
1.       SQL Injection
2.       Cross Site Scripting (XSS)
3.       Malware Execution
4.       Denial of service
5.       Cracking unsecured passwords
6.       Breaking of insecure Session Management
Security Practices in .Net
The basic security feature Authentication and Authorization should be used in applications to avoid and minimize the security threats. Let's see what is Authentication and authorization,

Authentication: -“ Authentication is the mechanism whereby systems may securely identify their clients positively. Authentication systems provide answers to the questions:
·         Who is the user?
·         Check whether the user exist or not in the system?
Types of Authentication:
 
1.       Forms based Authentication :- The logon form prompts credentials of user and the inputs are authenticated by means of the server
2.       Windows Authentication :- Authenticate the users to accessing the application by having their existing user accounts within the local user database of the Web server or Active Directory.
3.       Passport authentication :- Authenticate by means of web service provided by Microsoft's Passport, Which is a centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites.


Authorization: - It is the mechanism by which a system determines what level of access a particular authenticated user should have to secure resources controlled by the system. In simple, user has right to access specific data or not.
Types of Authorization:-
1.            URL Authorization
2.            File Authorization
3.            Authorization based on ACLs

Google's "GO"

Google released of a new, open sourced programming language called Go. The company says that Go is experimental, and that it combines the performance and security benefits associated with using a compiled language like C++ with the speed of a dynamic language like Python.


Here’s how Google describes Go in its blog post:

Go attempts to combine the development speed of working in a dynamic language like Python with the performance and safety of a compiled language like C or C++. In our experiments with Go to date, typical builds feel instantaneous; even large binaries compile in just a few seconds. And the compiled code runs close to the speed of C. Go is designed to let you move fast.

We’re hoping Go turns out to be a great language for systems programming with support for multi-processing and a fresh and lightweight take on object-oriented design, with some cool features like true closures and reflection.

For more details check out Golang.org.