Solved

My first SQL program.

Posted on 2008-10-01
4
567 Views
Last Modified: 2010-04-21
I am just learning how to use SQL 2005 and my first program is not working.  My operating system is windows XP and I downloaded SQL 2005 free trail from the web site.  When I executed my program I received a list of errors:
Msg 170, Level 15, State 1, Line 8
Line 8: Incorrect syntax near 'NAME'.
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'Table'.
Msg 156, Level 15, State 1, Line 24
Incorrect syntax near the keyword 'Table'.
Msg 156, Level 15, State 1, Line 28
Incorrect syntax near the keyword 'TABLE'.

I am unable to figure out what is wrong.
My code is below.  Any help will be most appreciated.

CREATE DATABASE Kudler_Fine_Foods
      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods.mdf',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
LOG ON
      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods_LOG.LDF',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
GO
-- =========================================
-- Create table template
-- =========================================

CREATE TABLE Employee Table
 (
       Employee_ID varchar (3) NOT NULL,
       Last_Name VARCHAR (30),
       First_Name VARCHAR (30),
       Address VARCHAR (45),
       City VARCHAR (15),
       State VARCHAR (3),
       Telephone_area_code VARCHAR (3) NULL,
       ,...n
       Telephone_number VARCHAR (8) NULL,
       EEO-1 Classification VARCHAR (30),
       ,...n
       Hire_date VARCHAR (10) NULL,
       Salary VARCHAR (10)
       Gender VARCHAR (2),
       Age INT (2)
       Foreign  Key From Job Title table VARCHAR (50),
       CREATE UNIQUE INDEX Employee_ID
       ON Employee Table (Employee_ID
       PRIMARY KEY (Employee_ID)
 );

 CREATE TABLE Job_Title TABLE
 (
       EEO-1 Classification VARCHAR (30),
       ,...n
       Job_Title VARCHAR (50),
       Job Description VARCHAR (170),
       Exempt/Non-Exempt Status VARCHAR (3),
       PRIMARY KEY (EEO-1 Classification)
 );
 --=========================================--
 -- Insert Data into Employee Table
 --=========================================--

 INSERT INTO [Kudler_Fine_Foods].[dbo].[Employee]
 (
       [Employee_ID], [Last_Name], [First_Name], [Address], [City], [State],
 [Telephone_area_code], [.....n], [Telephone_number], [EEO-1
 Classification], [....n], [Hire_date], [Salary], [Gender], [Age], [Job
 Title]
 )
 VALUES
 (
       '1', 'Edelman', 'Glenn', '175 Bishops Lane', 'La Jolla', 'Ca', '619', '', '555-0199', 'Sales Workers', '', '10-07-2003', '$21,500', 'M', '64', 'Cashier'
 )
0
Comment
Question by:Mystified-One
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22619514
You can view the syntax for creating databases here:
http://msdn.microsoft.com/en-us/library/ms176061.aspx


CREATE DATABASE Kudler_Fine_Foods
on      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods.mdf',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
LOG ON
      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods_LOG.LDF',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
GO

 CREATE TABLE Job_Title TABLE
should be  
CREATE TABLE Job_Title

TABLE goes before, not after

don't put numeric values

 INSERT INTO [Kudler_Fine_Foods].[dbo].[Employee]
 (
       [Employee_ID], [Last_Name], [First_Name], [Address], [City], [State],
 [Telephone_area_code], [.....n], [Telephone_number], [EEO-1
 Classification], [....n], [Hire_date], [Salary], [Gender], [Age], [Job
 Title]
 )
 VALUES
 (
       '1', ....

in quotes

 INSERT INTO [Kudler_Fine_Foods].[dbo].[Employee]
 (
       [Employee_ID], [Last_Name], [First_Name], [Address], [City], [State],
 [Telephone_area_code], [.....n], [Telephone_number], [EEO-1
 Classification], [....n], [Hire_date], [Salary], [Gender], [Age], [Job
 Title]
 )
 VALUES
 (
       1,
0
 

Author Comment

by:Mystified-One
ID: 22619624
So if I am reading correctly I need a add

CREATE DATABASE database_name
    [ ON
        [ PRIMARY ] [ <filespec> [ ,...n ]
        [ , <filegroup> [ ,...n ] ]
    [ LOG ON { <filespec> [ ,...n ] } ]
    ]
    [ COLLATE collation_name ]
    [ WITH <external_access_option> ]
]
[;]

To attach a database
CREATE DATABASE database_name
    ON <filespec> [ ,...n ]
    FOR { ATTACH [ WITH <service_broker_option> ]
        | ATTACH_REBUILD_LOG }
[;]

in front of my program?
0
 

Author Closing Comment

by:Mystified-One
ID: 31502191
I need to fully read the information from the link and work with it before knowing if it fully answers my question.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22620121
I'm not sure your use of the word "program" is correct.  What you are writing is a SQL script.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question