CREATING TABLES IN TO DATABASE:-
Hello Friends,
In my first article I have explained how to create new database along with database files. Now I am happy to publish my second article in to http://www.dotnetspider.com/ .It is useful for beginner's
who are learning SQL Server 2000 database. Now you learn how to create table in database. Before creating the table you need to understand table structure in database.
Microsoft SQL Server 2000 is RDBMS database. RDBMS database is a collection of related data, which
is stored in the form of tables. It is manage efficiently, negligible run time error and retrieve related column data very soon. Every table has rows and columns called attributes so that it is easier way to manage entire data with out any cross confusion. Now you learn how to create table and update data in to table.
MOST POPULAR RDBMS DATABASE:
1. MS SQL Server 7.0 - Microsoft Corporation.
2. MS SQL Server 2000 - Microsoft Corporation.
3. Oracle 9.0 - Oracle Corporation.
4. Sybase - Sybase Inc.
5. Informix Server - Informix Software Inc.
Data Store in database in the form tables that are arranged by rows and
columns. Every columns store specific information depends on data type.
Some useful data types are:
Binary, integer, string, approximate numeric, exact numeric, date and time, money,
auto increment, user defined etc.
BASIC NEED FOR CREATING TABLE: -
- Identify table name.
- Identify attributes of the table.
- Identify the data item that need to be stored
- Identify the data types.
- Specify the length of attributes.
- Identify Nullability in data types.
Represent data in the form of table- Table is a database objects used to store related data. Maximum of 1024 column is allowed per table and max. Of 8060 byte is allowed per row in SQL Server 2000. Here I have creating the table for Singapore Airways.
Attributes of tables are:
USE EMPLOYEE
CREATE TABLE PASSENGER
(
PRN_NO CHAR (8) NOT NULL,
FIRSTNAME CHAR (20) NOT NULL,
LASTNAME CHAR (20) NOT NULL,
AGE INT NOT NULL,
GENDER CHAR (1) NOT NULL,
TRAVELDATE DATETIME NOT NULL,
CLASS CHAR (5) NOT NULL,
SEATPREF CHAR (15) NOT NULL,
MEALPREF CHAR (15) NOT NULL,
SEATZONE CHAR (10) NOT NULL,
SSR VARCHAR (100) NOT NULL,
STATUS CHAR (15) NOT NULL,
CANCELFLAG CHAR (4) NOT NULL
)
Press F5 to execute the statement.
Check whether the table has been created.
SP_HELP PASSENGER
INSERT A ROW INTO THE TABLE:
After the table structure has been created, data can be inserted into the table.
You can insert row data into table by using INSERT command.
INSERT PASSENGER VALUES('I100','Aman','John','25','M','21-MAR-2005','Eco','Luxary','Yes',
'North’,’ Registration id done before the selection','YES','0')
Press F5 to execute.
Verify the inserted row and column data by using following query.
SELECT * FROM PASSENGER
DROP TABLE FROM DATABASE:
You can remove the table from the database when it is not useful by
writing query DROP TABLE.
When table is dropped from database all the data is also deleted.
Syntax
DROP TABLE PASSENGER
Then verify the deleted table by using query.
SELECT * FROM PASSENGER
The following command views the table structure.
SP_HELP PASSENGER
You get the following output,
The object 'passenger' does not exist in database 'pubs'.