Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Using sp_tableoption and getting an error.

Posted on 2004-08-09
7
712 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 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: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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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

Thanks.

Richard Quadling.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
t-sql need help on t-sql 10 25
SQL Dump exec output to table 3 21
VB.NET Application Installation with sqlserver 8 29
Getting invalid Syntax SQL. 3 19
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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

856 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