Creating a SQL Server Database STEPS IN CREATING A DATABASE IN 3 SIMPLE STEPS Understand the problem. Think of the essential data elements which are to become a part of the database Create the database using the SQL server 2008 – Command Prompt Feed data into the database Lets take a look at how this can be done
Step 1: Understand the problem Analyze the problem and abstract the essential details that are to be stored For example, if you wish to construct a database of the grocery items that are to be bought, the essential facts would be:
We need not bother about the ‘less’ significant data like ISI certificate number or the Ingredients from a daily-user’s perspective Bottom-line: Take the important stuff, ignore the rest.
Step 2: Create the database The Next step is to create the database schema. The schema (pronounced as skee-ma) is the structure of the database, which is described in a DBMS language like SQL. For the Grocery-Database, the schema of a table of items may look like: The Item number is a key, i.e., it is used to uniquely locate a product in a database.
Step 2: Create the database Searching a DB Without a Primary Key: NOT EFFICIENT Computer: Now which out of these do you need? User: Search for ‘Milk’ Database is searched and 2 entries match
Step 2: Create the database Searching a DB witha Primary Key: EFFICIENT Computer: I got it! User: Search for Item with ID 102 Database is searched and 1 entry matches DB With a Primary Key Hence, always include primary keys in your DB deign
Step 2: Create the database Creating the DB using SQL Server 2008 – Command Prompt
Step 2: Create the database The SQL Language consists of 3 major subsets, based on the nature of the commands:
Step 2: Create the database The SQL command for database creation falls under the DDL Language as it lets the user ‘define’ the database structure 1.Open the SQL Server Command Prompt:
Open Command Prompt:
Click on START-> RUN-> Type ‘cmd’
Activate SQL Command Prompt
Type ‘sqlcmd’ in the command prompt that was opened
Step 2: Create the database 2.Type the Command The Syntax of the table-creation command is: create table <table-name> ( <fieldNamefieldTpye>,…); The Common Attributes/Fields types are:
Step 2: Create the database For example, consider a Grocery Item database: Field Type: Number Field Type: String Field Type: Float (Decimal) Field Type: Date So, command for creation would be: create table itemlist (ItemID number, ItemName varchar2(15), cost float, dataofpurchase date); NOTE: Dont worry about the ‘case’ of the field-names. SQL is case insensitive.
Step 2: Create the database 3. Runthe Command In the SQL Command prompt, after typing the command: create table <table-name> ( <fieldNamefieldTpye>,…); 1> Type ‘GO’ and press ENTER to run the SQL Server command: 1> create table <table-name> ( <fieldNamefieldTpye>,…); 2> go
Visit more self help tutorials Pick a tutorial of your choice and browse through it at your own pace. The tutorials section is free, self-guiding and will not involve any additional support. Visit us at www.dataminingtools.net