Solved

Using sp_tableoption and getting an error.

Posted on 2004-08-09
7
706 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:RQuadling
  • 4
  • 2
7 Comments
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 70 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:RQuadling
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 40

Author Comment

by:RQuadling
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:RQuadling
ID: 11751082
Increased points for the additional question.
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 80 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:RQuadling
ID: 11751163
Thanks for that.
I've dropped the "text in row" and moved to nvarchar().

Thanks.

Richard Quadling.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

919 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

19 Experts available now in Live!

Get 1:1 Help Now