?
Solved

Using sp_tableoption and getting an error.

Posted on 2004-08-09
7
Medium Priority
?
746 Views
Last Modified: 2010-08-05
Hi.

I am creating an SQL Script which will create a database.

The database is a conversion from a non SQL database.

A part of the script is ...

/****** Object:  Table [dbo].[AcceptCode]    Script Date: 09/08/2004 10:31:28 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AcceptCode]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AcceptCode]
GO

/****** Object:  Table [dbo].[AcceptCode]    Script Date: 09/08/2004 10:31:28 AM ******/
CREATE TABLE [dbo].[AcceptCode] (
      [UniqueID] [int] IDENTITY (1, 1) NOT NULL  ,
      [AcceptCode] nchar(3) ,
      [Description] nchar(40) ,
      [SummaryCode] nchar(3) ,
      [SpareText] nchar(17)
) ON [PRIMARY]
GO

 CREATE  UNIQUE  INDEX [PK_AcceptCode] ON [dbo].[AcceptCode]([UniqueID]) WITH  IGNORE_DUP_KEY  ON [PRIMARY]
GO

exec sp_tableoption 'AcceptCode', 'text in row', 'ON'

(I am cloning the script style that MS uses when you use Create Script on a database, so hopefully, my script will look the same as the one MS produces when I have finished).

When I run this script, the tables are produced as required.
The index is produced too.

But I get an error on the exec sp_tableoption line.

The error is ...

Server: Msg 2591, Level 16, State 90, Procedure sp_tableoption, Line 79
Could not find row in sysindexes with index ID 255 for table 'AcceptCode'.

This comes from the sp_tableoption procedure.

Line 79 is ...

            BEGIN TRAN
            DBCC LOCKOBJECTSCHEMA(@TableNamePattern)
            dbcc no_textptr(@TabId, @intOptionValue) <<<<<<<<<<<<<<<< Line 79
            COMMIT TRAN

I've just started with MS SQL Server, so I am not sure what I should be doing next.

Ideas/suggestions/etc.

Please.

Thank you.

Richard Quadling.
0
Comment
Question by:Richard Quadling
  • 4
  • 2
7 Comments
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 280 total points
ID: 11751031
Hi Qualding,

<BOL>
sp_tableoption
Sets option values for user-defined tables. sp_tableoption may be used to turn on the text in row feature on tables with text, ntext, or image columns.
</BOL>

You table has no such field.

Text is a datatype
ALthough nchar can be used to store "text" - a string - , it's not TEXT datatype
0
 
LVL 17

Expert Comment

by:BillAn1
ID: 11751036
The TEXT IN ROW option is only for text datatypes. You don't have any columns which are text, they are all nchar, so you don't need the option. Infact, as is happening, you get an error if you try to set the option on a table which has no text columns.

BTW, you might consider using nvarchar(), particularly if your description is not always a full 40 chars in length.
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751043
Oh stupid me.

I've been reading and reading the "text in row" page in the Books Online.

I saw it said ...

"You enable the text in row option for a table by using sp_tableoption. With the text in row option set to ON, Microsoft® SQL Server™ 2000 stores text, ntext, or image strings directly in the data row if:..."

And I STILL went ahead and used nchar as the "text" type!

DOH!

Just re-testing script.

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751081
Hi.

Changed nchar to ntext and dropped the length part, and all is now working.

But BillAn1 raises a good question.

My existing database has text strings upto 255 characters in length and is NOT unicode.

I am converting the app to SQL and making it web based.

The app does need to allow for non ascii letters (european mainly). Do I need national format or not.

And would varchar be better/same as using "text in row" with ntext?

Richard.
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751082
Increased points for the additional question.
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 320 total points
ID: 11751140
(var)char is always better for text < 8000 chars. There are a lot of limitations on what you can do with a text datafield. Generally, you should think of it as a 'blob' of data, that you can't parse very well.
regards the languages, depends a bit on what amount of flexibility you want. the standard Latin colation does have most of the normally used characters in european languages, but unicode is more 'robust', and more flexible, so you might be safer to use nvarchar rather than varchar.
0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 11751163
Thanks for that.
I've dropped the "text in row" and moved to nvarchar().

Thanks.

Richard Quadling.
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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

840 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