How To Determine Length Of Table Row In Sql 2005
Sep 14, 2006How, other than by doing the addition on my own, can I detemrine the length of a row in a table?
TIA,
barkingdog
How, other than by doing the addition on my own, can I detemrine the length of a row in a table?
TIA,
barkingdog
In SQL Server 2005,here are two tables, created by the following SQL Statements:
CREATE TABLE student(
ID CHAR(6) PRIMARY KEY,
NAME VARCHAR(10),
AGE INT
);
CREATE TABLE score(
ID CHAR(6) PRIMARY KEY,
SCORE INT,
FOREIGN KEY(ID) REFERENCES student(ID)
);
For the length of Column ID is not enough, So I want to alter its length.The alter statement is:
ALTER TABLE student ALTER COLUMN ID CHAR(20)
For the table student is referenced by table score, the alter statement can not alter the column of the table student, and the SQL Server DBMS give the errors.
But, I can manually alter the length of the column ID in SQL SERVER Management Studio. How to alter column length of the master table(student) along with the slave table(score)?
Thanks!
is there any way or a tool to identify if in procedure the Parameter length was declarated less than table Column length ..
I have a table
CREATE TABLE TEST001 (KeyName Varchar(100) ) a procedure
CREATE PROCEDURE SpFindNames ( @KeyName VARCHAR(40) )
AS
BEGIN
SELECT KeyName FROM TEST001
WHERE KeyName = @KeyName
END
KeyName = @KeyName
Here table Column with 100 char length "KeyName" was compared with SP parameter "@KeyName" with length 40 char ..
IS there any way to find out all such usage on the ALL Procedures in the Database ?
For those of you who would like to reference my exact issue, I'm dealing with the RSExecution SSIS package at the "Update Parameters" data flow task, at the Script Component.
The script tries to split parameter data into name and value. Unfortunately, I have several reports that are passing parameters that are very large. One example has over 65,000 characters all in the normal "¶mname=value&parm2=value..." format.
The code in the script works fine until it gets to one of these very large parameter sets. I have figured out what is causing the issue. Here's some code:
Dim paramBlob as Byte()
paramBlob = Row.BlobColumn.GetBlobData(0, Row.BlobColumn.Length)
The second parameter of the .GetBlobData function takes an INTEGER as its count! Therefore, no matter what kind of datatype I pass to the string that the script will later split, it will be limited to 32767 characters.
THIS IS A PROBLEM!!!
Does anyone know a workaround for this issue? I need all of the parameter data to be reported, and I would hate to have to skip over rows like this. Also, if I'm missing something, please fill me in!
Thanks for your help in advance,
LOSTlover
I want to access sqlserver table properties from asp.net .How do i know that a table defined in sqlserver has autoincrement field or not.Actually i have to access all the tables in a database and execute different function for table with auto increment on and off.
I am not being able identify this property from codes.Please help.thank you
Does anybody know of a way to determine the last date/time a table has been accessed (query/update)? I've done enough research to know that this isn't easy. However, perhaps somebody has figured out a way through some of the stats that SQL Server keeps to determine the last access of a table. I have recently been put on a team that had no DBA and has a number of databases out there. They would like to determine which databases are inactive and get rid of them. I am a developer and haven't had much SQL Server Administration experience. Any info will help greatly! Thanks!
View 2 Replies View RelatedHi all,
I am looking for a query to determine the exact size of a large table.
Thanks
JJ
Does anyone have a script that analyzes primary and foreign key relationships of tables and produces a suggested load order based upon dependancies?
Thanks,
Fred.
I have a requirement based on 2 parts to determine a row of data in a table through SSIS :
a. Work out the LEG_SEQ_NBR of the VESSEL, VOYAGE and LEG already stored in table1.
To do this join table1 and join table2 through BL_ID column.
b. Work out the 2ndVESSEL, 2ndVOYAGE and 2ndLEG.
Once we have identified the LEG_SEQ_NBR of the VESSEL,VOYAGE, LEG already stored in table1 we need to add '1' to this value and then find that LEQ_SEQ_NBR in table2.
The DDL of table1 and table2 along with the test data are as below:
CREATE TABLE [dbo].[table1](
[BL_ID] [decimal](10, 0) NOT NULL,
[VESSEL] [nvarchar](10) NULL,
[VOYAGE] [nvarchar](12) NULL,
[LEG] [nchar](3) NULL,
[Code] ....
For Example:
BLNO = 21 and BL_ID = 1
Current Vessel/Voyage/Leg in table1 = CEUR 032E E
LEG_SEQ_NBR of this Vessel/Voyage/Leg in table1 = '1'
Therefore if we add '1' to this value we'd be looking for LEG_SEQ_NBR '2' as the 2ndVESSEL,2ndVOYAGE,2ndLEG.
In this case that would = MARB 794S S
How this can be worked out through an SSIS job ?
I would need to rewrite SQL code to determine that id is unique in the Customer table.
My two tables are:
CREATE TABLE CUSTOMER(
[CUSTNO] varchar(5) NOT NULL,
[ID] CHAR(9) NOT NULL,
[NAME] VARCHAR(128) NOT NULL,
[ADDRESS] VARCHAR(128) NOT NULL,
[DATEOFBIRTH] DATE NOT NULL,
[Code] ....
Good Morning
Is There anyway to determine the table you are referencing in a trigger's inserted / deleted tables?
i.e would this be possible
print @Table_Name + " was Updated"
Where @Table_Name is the table on which the trigger is created
(bad example I know but you get the idea)
Any input will be appreciated.
I need a SQL or TSQL command (not a stored procedure) that will determine if a table exists (TBL_PARAMETERS). The command needs to return a 1 if the table exists or 0 if it dose not exist.
Thanks!
Sean
How can I determine if SP1 is installed for SQL Server 2005?
TIA
We have serveral app groups that have installed SQL 2005 Express, but each group have installed different components. How can I determine, specifically if the following components were previously installed.
ADDLOCAL=SQL_Engine
ADDLOCAL=SQL_FullText
ADDLOCAL=RS_Server
And if not installed re-install with the missing component??
Thanks
Tony Z
code that I can use to determine if a certain table has been accessed in the past?
View 6 Replies View RelatedHi all,
I'm new to this whole trigger 'thing', so forgive me if this question has been asked and answered a few times already.
I'm in the process of writing a trigger that will send an e-mail to an application admin when any table within a given database is altered (IE, a column is added or deleted). I can get the e-mail to fire off when that happens without any issue, but I'd like to be able to let the admin know which table was tweaked and what new column was added.
Is this a relatively easy thing to do and I'm just not finding the right built-in variable name, or does something more need to be done?
Thanks,
-Mike
I have created a table in the sql server 7.0 and I wanted to know the what is the size of the table, is there any storeprocedure or command that can be used to measure the space used by the table in the database
View 2 Replies View RelatedHi,
Does any one know how to find a record (row) length of a table?
Hi,
I want to export one CSV file to a SQL table.
My problem is my Csv File is variable length file like :
000;1;amruth;20000
000;1;amruth;20000;praveen;shell;floor11
000;1;amruth;20000;praveen;shell;floor11;aaa;aa;aa;aa;aa;aa;aa
Sql Table is like col1- - - - - - - Col 15
I want to make a package to import that variable length Csv to This Sql table like
000 amruth 20000 Null Null Null Null Null Null Null Null Null Null
000 amruth 20000 Praveen shell floor11 Null Null Null Null Null Null Null
000 amruth 20000 Praveen shell floor11 aaa aa aa aa aa aa aa
I hope you got the problem.
I tried with BulkInsert using ; as column Delimiter and as Row Delimiter
and Flat File connection with Same Delimiters but its not working.
its importing like :
000 1 amruth 20000
000 1 amruth 20000;praveen;shell;floor11
000 1 amruth 20000;praveen;shell;floor11;aaa;aa;aa;aa;aa;aa;aa
its inserting like this in 4th column.
If any body can help me on this please reply Asap.
Thanks in advance
Hi all,
I ve few queries regarding SQLServer 2005, kindly help me to understand the things,
1. Datatypes like nvarchar, varchar, varbinary use 'max' to define their datalength,
a. is this 'max' always has the value of 2^31-1 ?
b. what other data types in sqlserver 2005 can use 'max' to define their datalength?
2. I defined a table (say 't') with a column 'name' of datatype nvarchar(max), now tried to execute the below query in the SQLServer client,
select column_name, data_type, character_maximum_length from information_schema.columns where table_name='t'
the result is,
+--------------+------------+--------------------------+
| column_name | data_type | character_maximum_length |
+--------------+------------+--------------------------+
| name | nvarchar | -1 |
+--------------+------------+--------------------------+
The question is why the datatype length is returned as -1, what happened to 'max'?
is there any other way to retrieve the actual data length (ie., 'max') from the table definition?
-Sn
Hi! I am new to SQL Server... looking for some veteran assistance.
"Data Integrity Report"
I need a Stored Procedure that takes a table name as a parameter and returns a cursor suitable as a data source for a pre-built Report Services report (I guess Report Services would call the SP?).
The cursor/report needs to have the following columns:
Ordinal_Position (I.E. Column number)
Column_Name
Number Of Blank Rows (how many missing values for this column in this table)
Difference (Between total rowcount and population of this column)
Data_Type
Column_Length (either Character_Maximum_Length or the numeric widths rolled up with COALESCE?)
Sample Data (The contents of the "first" row in the table, based on a TOP(1) and ORDER BY xxx)
The report should look like this (for a table with 100 rows):
Col Num Col Name # Blanks Difference Data Type Col Length Sample Data
1 Name 12 88 varchar 30 Sally Smith
2 Address 34 66 varchar 45 123 Main St Apt 45
3 Acct_ID 0 100 varchar 4 AB12345
Using the "Information_Schema.Columns" I can get everything I need except for #3 (blanks count) and #7 (Sample data).
Is it possible to do this as 1 query, with a CTE or APPLY or something, or do I need to do a table variable based on the Information_Schema and then use dynamic SQL and row-by-row COUNT(*) for each column? And the same for the Sample Data.
Sorry for the long post, and thanks in advance!
John
I am trying to narrow down this problem. Basically, I added 3 columns to my article table. It holds the article id, article text, author and so on. I tested my program before adding the additional field to the program. The program works fine and I can add an article, and edit the same article even though it skips over the 3 new fields in the database. It just puts nulls into those columns.So, now I have added one of the column names I added in the database to the code. I changed my businesslogic article.vb code and the addarticle.aspx, as well as the New article area in the addartivle.aspx.vb page. The form now has an additional textbox field for the ShortDesc which is a short description of the article. This is the problem now: The command parameters.length is 9 and there are 10 parameter values. Right in the middle of the 10 values is the #4 value which I inserted into the code. It says Nothing when I hover my mouse over the code after my program throws the exception in 17 below. Why is command parameters.length set to 9 instead of 10? Why isn't it reading the information for value 4 like all the other values and placing it's value there and calculating 10 instead of 9? Where are these set in the program? Sounds to me like they are hard coded in someplace and I need to change them to match everything else. 1 ' This method assigns an array of values to an array of SqlParameters.2 ' Parameters:3 ' -commandParameters - array of SqlParameters to be assigned values4 ' -array of objects holding the values to be assigned5 Private Overloads Shared Sub AssignParameterValues(ByVal commandParameters() As SqlParameter, ByVal parameterValues() As Object)6 7 Dim i As Integer8 Dim j As Integer9 10 If (commandParameters Is Nothing) AndAlso (parameterValues Is Nothing) Then11 ' Do nothing if we get no data12 Return13 End If14 15 ' We must have the same number of values as we pave parameters to put them in16 If commandParameters.Length <> parameterValues.Length Then17 Throw New ArgumentException("Parameter count does not match Parameter Value count.") 18 End If19 20 ' Value array21 j = commandParameters.Length - 122 For i = 0 To j23 ' If the current array value derives from IDbDataParameter, then assign its Value property24 If TypeOf parameterValues(i) Is IDbDataParameter Then25 Dim paramInstance As IDbDataParameter = CType(parameterValues(i), IDbDataParameter)26 If (paramInstance.Value Is Nothing) Then27 commandParameters(i).Value = DBNull.Value28 Else29 commandParameters(i).Value = paramInstance.Value30 End If31 ElseIf (parameterValues(i) Is Nothing) Then32 commandParameters(i).Value = DBNull.Value33 Else34 commandParameters(i).Value = parameterValues(i)35 End If36 Next37 End Sub ' AssignParameterValues38 39 40 41
View 2 Replies View RelatedI am working on a migration project and need to derive the total length of the columns for a particular table. I have the following query designed for the same:
select
t.name,
sum(c.max_length)
from sys.all_columns c
join sys.all_objects t
on t.object_id = c.object_id
where t.name='test_1'
group by t.name
;
This query gives me correct results except for data types varchar(max), nvarchar and xml for which the max_length is stored as -1 which causes my results to be incorrect when summed up. Is there any other way to find out the maximum data length for such type of columns?
Here is my table DDL:
CREATE TABLE [dbo].[TEST_1](
[COL_1] [bigint] NULL,
[COL_2] [bit] NULL,
[COL_3] [char](10) NULL,
[COL_4] [date] NULL,
[code]....
using SQL (server man studio) EXPRESS
when I create a table
I only see... (col-column)
col name ; Data type ; ALLOW NULLS
how can I set the length of an integer field
or is it because it is so express, I just have to set up the data type -- such as integer
M A N Y THANKS
Hi,
I have a table with 500 columns, most of them are type of varchar. I would have the following data set:
ColumnName DataTypeLength MaxLength
-------------------- -------------------- -------------------
ColA 50 42
ColB 10 7
ColC 50 8
.... ... ...
I can have a query to get the data type length (hom many varchar) for each columns:
SELECT column_name, data_Type, character_maximum_length
FROM information_Schema.columns
WHERE table_name='***'
ORDER BY ordinal_position
but I have problem to get the actual maximum length of the each column. Anybody have the similar query?
thanks,
Folks:
I would like to know the total length of data type in a table. I ran the following query. Will this give me the correct information? I also ran sp_columns <table name> and it too give the length. But There is a difference in the numbers. Am I doing something wrong and which is the correct the query or sp_column.
select sum(length) from syscolumns
where id in (select id from sysobjects
where name = 'XYZABC')
sp_columns XYZABC
Thanks !
Can I increase the length of a varchar column of table involved in transactional replication without dropping and recreating publication/subscription?
Any help/short-cuts/undocumented features greatly appreciated.
Regards
Opal
How do I determine the read/write frequency on a database table? I am trying to do this on a 2012 and 2008 R2 servers.
View 2 Replies View RelatedHi,
I am new at sql 2000 and 2005, I have created a package in 2005 which I am trying to execute on a daily bases by creating a job. At first because of security issues the job would not execute. Hence, I had to create a credential and a proxy to run the job with sa account. Now it is giving me this error,
€œSQLServer Error: 536, Invalid length parameter passed to the SUBSTRING function. €œ
Through research I have no clue as what I need to do, or where to look.
The package runs without error when I execute the package itself.
Any help is greatly appreciated.
Thanks,
Lori
Hi
I was wondering if anyone has an idea of how we could find the table names and column names of the tables in our Sql server database at runtime/dynamically given our connection string? Please let me know.
Thanks.
Hi all,
How to determine the value for the bar in Neural Network Viewer? I know the value is displaying in the tooltips when we pointing to the bar in the table but i don't know how to get them. So where can i get those of calculation or data of score, probability of value1 and 2, and lift for value1 and 2 ? Is it get from the Microsoft Neural Network Content Viewer? which column and how to calculate? If not, please advise.
Hope my question is clear.
I am looking forward to hearing from you shortly and thanks a lot in advance.
Thanks!
With best regards,
Yours sincerely,
xuenly
I am trying to determine the next available order id using the method below. It works provided the table has a record in it. If it doesn't I get the error "Input string was not in a correct format." I am certain that it is because the query is returning a value of NULL. How can get around that or check for the NULL value?' Establish data connection...Dim sqlConn As New SqlConnection(ConfigurationSettings.AppSettings("connectionstring"))'Determine order id number...Dim order_id As IntegerDim strSQL As StringstrSQL = "Select MAX(order_id) from mkt_order"Dim sqlCmd As New SqlCommand(strSQL, sqlConn)Dim sqlDA As New SqlDataAdapter(sqlCmd)Dim sqlDS As New DataSetsqlDA.Fill(sqlDS, "item")If sqlDS.Tables(0).Rows.Count <> 0 Thenorder_id = Convert.ToInt32(sqlDS.Tables(0).Rows(0)(0).ToString()) + 1Elseorder_id = 1End If
View 1 Replies View RelatedGood day,
We have a web application (ASP) running on SQL Server 7.0.
Recently, the users are getting quite a lot of timeouts on
the database:
Microsoft OLE DB Provider for ODBC Drivers error '80040e31'
[Microsoft][ODBC SQL Server Driver]Timeout expired
The database is not supposed to be doing too much work, so I can't
understand why these timeouts are occuring. How can I determine
the cause of the timeouts?
The cause could probably anything from a trigger that's taking
too long, a query that's taking too long, or simply bad database design.
I've looked at SQL Server's Profiler, but could not yet use it
successfully to give me any hints of what could cause the timeouts.
Any ideas of how I can use Profiler, Performance Monitor, or any other
tool(s) to see what is happening in the background in the database,
i.e. how much processing a trigger is using, etc.
Thanks very much!
---
Gert Lombard
OSI Airport Systems
South Africa