To maintain database in the form of table many database software are there like: Oracle, Sybase, FoxPro, and Ingress. To maintain a database firstly we have to create a table in the particular database software. In this article we are discussing that how to create table in SQL.
We can create table in SQL in two ways:
· Create a table by its own
· Creating a table by another existing table
How to create a table?
Each table includes some columns in it like a employee table contain name, eno, salary, mgrno, deptno etc. The "CREATE TABLE" command is used to create this type of table with all the columns defined uniquely. Each column has minimum three attributes:
· Name
· Data type
· Size
Each column definition within a table is separated through comma and finally in the end the SQL statement is ended with semicolon (;). Rules for creating a table:
1. A name can have length up to 32 characters.
2. For table name characters from A-Z and a-z and numbers form 0-9 are allowed.
3. Table name should begin with alphabet.
4. Reserve words are not allowed.
Syntax for creating a table:
Create table ( (), ( (), ................................................., ( ());
Here create table is the reserve word. At you can give any suitable name that you want to give to your table. Than within a bracket you have to give column name with suitable datatype and suitable size e.g. if you want to create table employee with name, rollno, fees, marks, percentage. It can be done as:
Create table student (name varchar2(20), rollno number(4), marks number(3), percentage number(4,2), fees number(5));
It will create the table named "student" with the columns name, rollno, marks, percentage, fees. Now you can insert values within it.
How to create table by a existing table?
It can be done by "AS SELECT" command. Syntax is:
create table (, ....................., ) as select , ... from ;
Here first table name is the name of table that you want to create and second name is the name of table from that table you want to create your new table. First table is called "target" table and second one is known as "source" table. You can also specify "where" that is condition clause also to specify some condition. Example:
Create table account_details (acct_no, balance) as select (acct_no, balance) from account_master;
The data type and size of column of target table will be same as that of source table.
Published by Harsh Gupta - Tech Writer
I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com View profile
- SQL Injections - the BasicsThis article will show you how to find a vulnerability, exploit it and how to prevent hackers from doing it to your website.
Easy SQL Queries Are in ReachAnyone can access and manipulate database information by understanding the select, from and where clauses of a Structured Query Language (SQL) query- How to Set the Table for a Dinner PartyRemember the rules of table settings with these tips and suggestions for both the casual and formal dinner table. You'll find easy tips and suggestions to make sure you know all the right guidelines, with easy to rem...
- How to Make a Kitchen Table Base Out of Vintage Crochet MalletsThis Kitchen Table Base Out of Vintage Crochet Mallets is the perfect designer look for a retro or vintage kitchen.
Thanksgiving Dinner Table Place Settings for Under $5am always on the look out for affordable and elegant table settings for the holiday. Thanksgiving is the perfect time to display photos of family, hand made projects, and small...
- Display Table Information by SQL
- How to Create a Stored Procedure in SQL Server 2000
- How to Create a Linked Server in Microsoft SQL Server
- The Date and Time on SQL Server 2008
- An Introduction to SQL and Its Purpose
- The Function of SQL: Databases Constructed with Object-Oriented Languages
- Database Table Data Types
- To maintain database in the form of table many database software are there
