As a database developer you will be working on following objects.
- Primary Key
- Foreign Key
- Unique Key
- Default Constraint
We will talk about all objects, mentioned above one by one.
Table :- Table is an object where information is stored in form of rows and columns in SQL Server.
Creating database table using T-SQL script.
Create table employee(Eid int,Name Varchar(100))
If we paste the highlighted script into the management studio window and click on “Execute” button(encircled with red color in the above image), a table with name “Employee” will be created in the database. If you see left side of the execute button you will see the database name selected as “Test“. It means that the table will be created in the “Test” database. You can select any already created database from the list. This time I have chosen “Test“.
Now lets See how to create a table using management studio.
For creating table using management studio, you need to expand the databases node that is right side in the above image and you find the test database that you have already created in past.Now you need to expand the “Test” node as well and in that node you will find tables node, just right click on the tables node. Now a menu will appear with option new table, you need to click on new table menu. As soon as you click on new table menu, a new type window will be opened in front of you.
Now lets have a look on the below snapshot.
In the above image, you can see three columns..
1)Column Name :- This column contain the names of the column that you have in your table.
2)Data type :- Data type of each column.
3)Allow Nulls :- You can specify if your column will contain null values or not.
I have created two columns in my table, now I want to save this table in SQL Server, To save this table into the database, we need to click on floppy icon, encircled by red color.
As soon as you click on save button(Floppy icon), a dialogue box will appear in front of you where we will enter the name of the table, I have put my table name as “Department“, just click on “OK” button of the dialog box and the table will be created in the database.
I hope after this article you will be able to create a table using management studio as well as through T-SQL script. In the next article I will talk about few more things related to tables that will give you more clarity. We will also talk about data types and different properties available to set while creating the table. Till then take care and have a wonderful day.
1,296 total views, 3 views today