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.
http://2.bp.blogspot.com/-gea2w633DIg/VqtrKb1t8xI/AAAAAAAAACg/RJJcGMI8YuQ/s640/db1.PNGEnter your server name and the click on "connect".
- after connecting your database engine right click on Databases in the object explorer.
http://3.bp.blogspot.com/-asRITkicKIY/VqttE7j8sFI/AAAAAAAAACs/sp5p6Jihgs8/s640/db2.png
- Enter your new database name, suppose we are creating our database with the name "User_Registration".
http://1.bp.blogspot.com/-p-htfGrXSKQ/VqtteQK0giI/AAAAAAAAAC4/ZXeiVCyR2FM/s640/db3.png
- 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.
http://1.bp.blogspot.com/-Sz10M87OLgo/Vqtuw1OtgHI/AAAAAAAAADA/u_E1RJXw73I/s400/db4.PNG
- 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.
http://4.bp.blogspot.com/-PmvK6tsgVoE/VqtvLoNiSUI/AAAAAAAAADM/oVLzx6aREns/s640/db5.png
- 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".
http://2.bp.blogspot.com/-MhBdVwa97fQ/VqtxQydzswI/AAAAAAAAADY/RXIOo3CFEtE/s640/db6.PNG
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".