Difference between revisions of "Creating tables in SQL Server"

From MyWiki
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
Foreign constraint prevents invalid data from being entered into the foreign key column. The foreign key value must be one of the values contained in the table it references.
 
Foreign constraint prevents invalid data from being entered into the foreign key column. The foreign key value must be one of the values contained in the table it references.
 +
 +
'''Creating a table using sql'''<br>
 +
 +
Use [Sample]<br>
 +
Create Table tblGender<br>
 +
{<br>
 +
ID int NOT NULL Primary Key,<br>
 +
Gender nvarchar(50) NOT NULL,<br>
 +
}<br>
 +
 +
Check the gui way of adding a foreign key  constraint <br>
 +
 +
Difference between nvarchar and varchar :<br>
 +
'''varchar:''' Variable-length, non-Unicode character data. The database collation determines which code page the data is stored using.<br>
 +
'''nvarchar:''' Variable-length Unicode character data. Dependent on the database collation for comparisons.<br>

Latest revision as of 01:11, 3 September 2015

Alter table table1 add constraint <name of constraint>
FOREIGN KEY (<column>) references table2 (<primary key column>)

Foreign constraint prevents invalid data from being entered into the foreign key column. The foreign key value must be one of the values contained in the table it references.

Creating a table using sql

Use [Sample]
Create Table tblGender
{
ID int NOT NULL Primary Key,
Gender nvarchar(50) NOT NULL,
}

Check the gui way of adding a foreign key constraint

Difference between nvarchar and varchar :
varchar: Variable-length, non-Unicode character data. The database collation determines which code page the data is stored using.
nvarchar: Variable-length Unicode character data. Dependent on the database collation for comparisons.