Friday 29 January 2016

SQL2- Table Creation in SQL server/Database Management System

A database consist of Tables, A table contain rows and columns, Columns contains the related information of specific item. A row contains columns information.

 In database, Columns are also known as "field" and rows as "records".
                    
      Lets create our first database which will contain one table with the name "Users_Table".
  • Open SQL server that you have installed on your machine. The first Screen looks like this.
      

  •  Enter your server name and the click on "connect".
  • after connecting your database engine right click on Databases in the object explorer. 


  • Enter your new database name, suppose we are creating our database with the name "User_Registration".
 


  • Under the databases folder our new database is created with the name "User_Registration".
  • Expand the User_Registration database in which our database contains the folder "Tables".
  • Right click on Tables and click on Table to create new table.



  • Now enter the desired column name under which you want to store your data.
  • Here we created four columns. These columns will contain related data with the name specified.


  • Whenever you create the table you must put first column for "id" and set "Primary Key" on id by right clicking on the id. id is a unique identifier because we set "Primary Key" on it which identify each individual record or row in a table.
  • id should have a data type integer (int).
  • Notice that other columns field contain data type "varchar(50)". varchar specify that every type of data can be input in the field either numeric values or either alphabetic values.
  • where 50 is the size of field. it can contain 50 characters.
  • One more important thing to be notice that at a time when you set primary key on the id there must be auto increment on id. There is "columns properties" on the bottom.
  • Click on "U_id" & in the column properties there is "identity specifications". expand "identity specification" and set (is identity) to "yes".

 
Identity Specification:
  This will increment in the id automatically whenever you enter individual record.

Identity Seed:
  identity seed is the option where you can provide your desired initial number from where you want to store record.

Identity Increment:
identity increment is the option where you set a value that tells how much increment you want in every record.

 Here we start storing record in U_id with a initial value of 1 which we specify in identity seed and we put a increment of 1 in the User_id.

  • Last step is to save the table with the desired name. By pressing Ctrl+S we save it with the name "Users_Table".




No comments:

Post a Comment