MS Sql Server: Creating A Database


Published on

Creating A Database

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

MS Sql Server: Creating A Database

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