Beruflich Dokumente
Kultur Dokumente
To specify see value and increment value to the auto increment column in the
existing databasetable, we pass parameter to the IDENTITY.
The 1st parameter is the initial value and the 2nd parameter is the step value.
In this case, the 1st row AutoId value will be 1 and 2nd row AutoId
value will be 6 and so on as theincrement parameter is 5.
To set existing column as primary key, run following sql script in the
Query window
In the above case, we are assuming that AutoId is a existing column in the
PersonalDetails table.
HereAutoIdcolumn will be set as primary key to the PersonalDetails table.
This adds a new column asAutoIdwith auto increment value and set this column as
Primary key ofthe table.
IDENTITY (1, 1) means the start value of the AutoId column value will be 1 and increment
by 1 for every new record.
Following are the data type and its range in SQL Server
To store any kind of integer data, we can use following data types. Notice the Range column
that isthe min and max limit of data we can store.
To store any decimal or numeric data, we can use following data types.
Numeric maps to the Decimal data type of the .NET and it is functionally
equivalent to the Decimaldata type.
To store small number with floating decimal point, float data type can be used.
To select a data type for a column (while designing) in the database table,
click on the Data type dropdown and selectit.
Notice the above picture, where LastName, Age, and Active column
Allow Nulls checkbox is checked that means that these fields will
acccept null value in the database table.
That will by default add a relationship in the left panel. Now click on the
button highlighted above.
Now click on the Primary key table dropdown and select PersonaDetails
and then click on the rowsbelow to select PersonalDetailsId from the
columns link and then in the Foreign key table below thetable name and
click the rows and select PersonalDetialsId, now click OK as shown
Creating Indexes in the database table columns helps us to search the data on that
particular easilyand quickly. The overall performance of the searching becomes
much better. When we create a primary key in the table, by default it creates
clustered index on the primary keycolumn.
Clustered Index:Clustered index sorts and stores the data rows in the table based
on theirkey values when we insert the record. In general, there is only one clustered
index in a singletable.
Nonclustered Index:A nonclustered index contains index key values and each key
valueentry has a pointer to the data row that contains the key value in the database
table.
It is generally created on columns other than primary key on which search
needs to be doneto improve the search performance.
So to create a clustered index, we do not need to do anything. Just creating a
primary key in thetable does the job.
Now click on Add button and change the (Name) value to some meaningful
name to make thisname unique. Now click on button that shows Index
Columns dialog box.
There can be more than one nonclustered index in a single table. However it
is suggested not tocreate unnecessary indexes as these indexes also has
an overhead and instead of increasingperformance it may decrease the
search performance.
Note that in the above insert statements, the second statement is inserting data into
LangDataNcolumn that is of nvarchar type and third statement is also inserting data
into LangDataN column butby prefixingN.
Now, the result looks like below