Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

My first SQL program.

Posted on 2008-10-01
4
Medium Priority
?
571 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

963 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