Solved

My first SQL program.

Posted on 2008-10-01
4
560 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
  • 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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now