Creating a table

Discussion in 'Databases' started by marburys, Jul 27, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi,
    I am trying to create a table in my database. When I run my script, I get an error accessing the master database saying I don't have proper rights. This script works just fine on my local SQL Server 2005 setup. What do I need to do to create tables here?
    Thanks,
    Jack
     
  2. Hi,
    Can you post the SQL?
    All the best,
    Mark
     
  3. Creating Tables

    Ok, here you go. I am used to having full control on my local SQL Server, but I am a little out of my element here. This is basically a hacked up and renamed version of the Northwind sample database (1 table only for now, just trying to get my feet wet).

    use SQL2005_572181_marbury
    go
    /*
    if exists (select * from sysdatabases where name='TestData')
    drop database TestData
    go
    */
    EXECUTE (N'CREATE DATABASE TestData
    ON PRIMARY (NAME = N''TestData'', FILENAME = N''' + N'TestData.mdf'')
    LOG ON (NAME = N''TestData_log'', FILENAME = N''' + N'TestData.ldf'')')
    go

    exec sp_dboption 'TestData','trunc. log on chkpt.','true'
    exec sp_dboption 'TestData','select into/bulkcopy','true'
    GO
    CREATE TABLE "Employees"
    (
    "EmployeeID" "int" IDENTITY (1, 1) NOT NULL ,
    "LastName" nvarchar (20) NOT NULL ,
    "FirstName" nvarchar (10) NOT NULL ,
    "Title" nvarchar (30) NULL ,
    "TitleOfCourtesy" nvarchar (25) NULL ,
    "BirthDate" "datetime" NULL ,
    "HireDate" "datetime" NULL ,
    "Address" nvarchar (60) NULL ,
    "City" nvarchar (15) NULL ,
    "Region" nvarchar (15) NULL ,
    "PostalCode" nvarchar (10) NULL ,
    "Country" nvarchar (15) NULL ,
    "HomePhone" nvarchar (24) NULL ,
    "Extension" nvarchar (4) NULL ,
    "Photo" "image" NULL ,
    "Notes" "ntext" NULL ,
    "ReportsTo" "int" NULL ,
    "PhotoPath" nvarchar (255) NULL
    )
    GO
     
  4. ...OK, when working with your remote server don't include the Database name and don't try and drop the database.
    If you remove the "use" it will default to your assigned SQL account, the one you are addressing/logged into.
    You also do not want to address System or Temp, just objects you have access to.
    In the SQL above you only need the commands for the table.
    On your account "create table" will work.
    All the best,
    Mark
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page