Sunday 23 September 2012

Methods to Create a Table in DB

In Previous post “SQL Table”, we’ve explained about the definition of the Table. This article will explain about “what are the ways we can create table in SQL Server”.

We can create a Table in Database in many ways, but most main method are,
  • Using SQL Scripts 
  • Using Database Tool
Using SQL Scripts: 

There are many database tools allow you to create tables without writing SQL State scripts, but given that tables are the container of all the data, all it is one of the fundamental object of the database, so it would be good if you learn thru SQL Scripts.

The CREATE TABLE statement is used to create a table in a database.

Syntax of CREATE TABLE:


Following are the basic syntax of creating a table
 

        Create table
        (
            column1 ,
            column2 ,
            column3 ,
            <...>  <...>  <...>
        )
Sample Table: EMPLOYEE
 

Execute the following Query at SQL Server management studio; it will create a Table called “Employee”
 

        Create table Employee
        (
            Emp_ID  int not null,
            First_Name varchar(50),
            Last_Name varchar(50),
            Date_of_Joining date,
            Department  varchar(50)
        )


Using Database Tool (SSMS):
 

In this method, we could create a table using the tool, SQL Server Management Studio(SSMS). 

Follow the steps below to create a table.
 

1. Open SSMS from Start Menu as shown below

2. Login/connect to the SQL Server by providing proper credentials


3. After logged in, Decide the database in which you are planning to create a table. Here am planning to create a table under “TestDB”, refer the exhibit below


4. Right click on the the Node “Tables”, select “New Table”


5. A spreadsheet will appear with 3 columns like “Column Name”, “Data Type”, “Allow Nulls”


6. Fill the sheet with columns name and its data type as shown below


7. Click Save Button from the Toolbar or Press Ctrl+S Keys
 

8. You will see a popup window with a input field, enter the table name here , press OK Button

Now you can see a new Table, Which you created, under Tables Node.


Hope this helps!.. please leave your comments here if you need any help on this..


Happy Learning.. :)

Sunday 9 September 2012

SQL Table

Tables are the basic structure where data is stored in the database. Hence table is one of the Database object.

Table consists of following Objects:-
  • Rows
  • Columns
  • Attributes
  • Relations
  • Data types
  • Constraints
  • etc.,
Table is a set of data elements (values) that is organized using a model of vertical columns and horizontal rows.

Note: A table has a specified number of columns but can have any number of rows.

What is RDBMS?

RDBMS is stands for Relational DBMS.
  • RDBMS is the extension of DBMS.
  • DBMS is built to support relational Model is known as RDBMS
  • DBMS are for smaller organizations with small amount of data, where security of the data is not of major concern and RDBMS are designed to take care of large amounts of data and also the security of this data.
  • In the Relational Data Model, Data represents in the form of table.
  • DBMS that stores the data in the form of Related Tables is known as RDBMS.
Refer the screenshot to know about various components of the basic Relational Model “Table”
 
Advantages of RDBMS:-
  • Single database can be categorized/split across different tables, which is differ from flat-file database that has one single table to store the entire database data.
  • In RDBMS, Same Database can be analyzed/viewed in different ways
  • RDBMS Data is structured in form of DB tables, records, fields, etc.,
Example for RDBMS:-
The most popular RDBMS are MS SQL Server, DB2, Oracle, MySQL and MS Access