473,508 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I determinate the data type of a physical table field

ad
I want to change a field a SQLServer table to varchar(10) if it is
nvarchar(5).

How can I determinate the data type of a physical table field in SQLServer
2005?

Dec 5 '06 #1
1 1300
Hi,

Issue a query using INFORMATION_SCHEMA.COLUMNS. For example, to get a
DataSet containing the column information of a table named, "YourTable" that
meet your specific requirements:

DataSet data = new DataSet();

using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(
@"SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'YourTable'
AND DATA_TYPE = N'nvarchar'
AND CHARACTER_MAXIMUM_LENGTH = 5", conn))
{
adapter.Fill(data);
}

// TODO: alter table
}

You can issue an ALTER TABLE T-SQL statement to perform the modification.

An alternative to this is SMO:

"Sql Server Management Objects"
http://msdn2.microsoft.com/en-us/library/ms162169.aspx

--
Dave Sexton

"ad" <fl****@wfes.tcc.edu.twwrote in message
news:Oh*************@TK2MSFTNGP02.phx.gbl...
>I want to change a field a SQLServer table to varchar(10) if it is
nvarchar(5).

How can I determinate the data type of a physical table field in SQLServer
2005?



Dec 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2019
by: Alexandre | last post by:
Hi, Im a newb to dev and python... my first sefl assigned mission was to read a pickled file containing a list with DB like data and convert this to MySQL... So i wrote my first module which...
13
2885
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify...
4
3252
by: Josh | last post by:
Hi, I am trying to write a function in a module in MS Access 2000 that will change the data type of a field called 'Start' in table 'bo_cpm_CS01ALL'. Here is the code that I have done so far...
2
2670
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
6
1579
by: Xero | last post by:
How do you determinate whether a varible of data type 'Char' is null or not? I used the following code, but it seemed that it didn't work: Dim ans As Char If ans = "" Then MsgBox("Ans...
13
4147
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture'...
0
14387
by: Grip | last post by:
Hi, I have gone throught the group and Microsoft's online help and have seen many suggestions but I am still seeking clarity: 1. I have an excel spreadsheet. Column A contains text that may...
9
3992
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
8
3254
by: mlwerth | last post by:
Dear Access Group: This is the most basic and most embarrassing of questions, but I cannot find where to change the data type of a text field that I have in Access 2003 to a number field. I've...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.