Tagged Questions

Specifies the type of data being stored (string, date, numeric, etc).

learn more… | top users | synonyms

2
votes
1answer
4k views

Changing a column data type from datetime to float

I have a table with a float column. All values in this column for all records are NULL. I want to change the data type to datetime. I executed the query: ALTER TABLE MyTable ALTER Column MyColumn ...
4
votes
1answer
365 views

Understanding MS SQL Server Date Types

Consider the following: declare @dt datetime, @dt2 datetime2, @d date set @dt = '2013-01-01' set @dt2 = '2013-01-01' set @d = '2013-01-01' select convert(varbinary, @dt) as dt, ...
-1
votes
1answer
229 views

Recommended datatype fixed length in mysql

What's the best data type for store fix length data such as MD5 password 1f3870be274f6c49b3e31a0c6728957f HEX Ccolor f2a709 They don't need character sets. All in absolute [a-z0-9]{6} for color, ...
1
vote
2answers
744 views

boolean purpose column char(0) or tinyint(1)

For Boolean purpose column which one is better: nullable char(0) or tinyint(1). I know bool is an alias for tinyint(1) , but in "High Performance MySQL" book that published by O'reilly said: "If ...
1
vote
1answer
281 views

Column of generic/variable type?

In SQL, I would like to create a table which can contain generic data types. This types can change from every row. The solution I could come up to is: CREATE TABLE TagValue ( tag VARCHAR(64), ...
0
votes
2answers
198 views

Should numeric identifiers like serial numbers be stored as integers?

Many of our databases store numeric tracking codes (like serial numbers) as integers. There is little chance of these codes every getting alphabetic characters, but it still seems like an incorrect ...
1
vote
2answers
226 views

Join on different types

In a database I have two tables: The first has a field named taxonomy_id that is an integer The latter has a field named ID that is a character varying The two tables are related: if it exists a ...
2
votes
1answer
94 views

Why does postgres use more space for a time with timezone than a timestamp with timezone?

The documentation on date/time data types state that timestamp with timezone takes 8 bytes, while time with timezone takes 12 bytes. They both have the same resolution (1 microsecond), and on the face ...
2
votes
1answer
578 views

Trigger doesn't run when value of a column changes from null to 1

I have this trigger: delimiter $$ create trigger tr after update on t1 for each row begin if new.col1 !=old.col1 then update t2 set col2 =1 where t2.col3=t1.col3; end if; end $$ This ...
3
votes
2answers
2k views

What data type should I use: ENUM, TINYINT, or CHAR?

I'm creating a new table and I would like to do it right. The table will be a list of members with their Professional Type and Decile associated. The Professional Type is a 3-character string. There ...
1
vote
1answer
112 views

Changing TEXT to VARCHAR

In a MySQL database (InnoDB) we have a table containing roughly 60.000.000 rows. One of the columns is of type text. Currently the longest entry has length 360 (found using SELECT MAX(LENGTH(value)) ...
24
votes
6answers
12k views

In what data type should I store an email address in database?

I understand that an 254 character email address is valid, but implementations I have researched tend to use a varchar(60) to varchar(80) or equivalent. For example: this SQL Server recommendation ...
0
votes
2answers
90 views

Adding a bool column; tracking untouched vs. false

[backstory] I have a simple database of our current Widget inventory. It averages just dozen columns across five or six tables, but has a huge number of records already. Some Widgets came with ...
6
votes
3answers
2k views

How to pass a table type with an array field to a function in postgresql

i have a table called book CREATE TABLE book ( id smallint NOT NULL DEFAULT 0, bname text, btype text, bprices numeric(11,2)[], CONSTRAINT key PRIMARY KEY (id ) ) and a ...
2
votes
1answer
1k views

Storing IPv4 and IPv6 hosts and networks

I have to store the IPv4/v6 address and networks(CIDR notation) in a MySQL database. Unfortunately, I am constrained to use Mysql. So, I'm looking for the equivalent of the inet type of PostgreSql. ...
2
votes
1answer
106 views

Oracle Table Design, Storing Small Values

In Oracle if you want to store a small value, such as a one digit code (e.g. 0, 1, 2, 3 4, or Null; or Null, or 1; or 1, or 2), what is the space optimal way to store such a value. Currently I'm ...
2
votes
1answer
591 views

SQL Server - storing ulong as primary key

I need to store ulong values as a primary key in SQL Server. Since SQL Server doesn't have a ulong datatype (or for that matter anything unsigned), the only way to go is to have column as ...
0
votes
2answers
144 views

looping through a table type variable

I have a function that has one parameter of a table type, i want to loop through all the fields and return the column that has a null or empty value. CREATE OR REPLACE FUNCTION ...
3
votes
1answer
2k views

query to identify all data types used in postgresql database tables

I don't want to know all data types, just all data types used in my database. Can this information be queried? PostgreSQL 8.4 and 9.x versions I currently need to know all data types for over 200 ...
1
vote
1answer
575 views

How can I restore the sql_variant_property of baseType back to a table variable in SQL Server

Ok, I know the title is confusing but here it goes. BTW I am using SQL Server 2008 I have a table that I am trying to use as a storage container. It has 3 columns: reportID integer, dataLabel ...
0
votes
1answer
1k views

What is the difference between int(8) and int(5) in mysql? [duplicate]

I found out, that if you have a field defined as INT(8) without ZEROFILL it will behave exactly as INT(5) in both cases the maximum value is −2,147,483,648 to 2,147,483,647, from −(2^31) to 2^31 − 1 ...
14
votes
2answers
923 views

Does varchar size matter in temporary tables?

There is a debate at my wife's work about just using varchar(255) for all varchar fields in temporary tables in stored procedures. Basically, one camp wants to use 255 because it will always work ...
4
votes
1answer
7k views

What is the benefit of using BOOLEAN over TINYINT(1)?

From MySQL manual, it says: BOOL, BOOLEAN These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true: I created a BOOLEAN column with ...
1
vote
1answer
5k views

Table schema column data type equivalents for Netezza 6 to SQL Server 2008

I'm trying to find a data type equivalents for data types in Netezza when migrating table schema to SQL Server. Where can I find a complete list? When getting down to brass tacks, I am specifically ...
0
votes
4answers
606 views

Writing SQL statement in sqlcmd to hide the milliseconds for column type of time

I have a table called testtable that have a column named expire_time of type [time] The problem is that when I type the following in sqlcmd: select * from testtable It will return the following: ...
0
votes
1answer
530 views

timeout on updating nvarchar(max) after converting datatype

I recently Upgraded to 2008 Enterprise and took the opportunity to change the biggest table in my db with the maintenance window. ran the following to change my ntext field ALTER TABLE ...
3
votes
1answer
560 views

Does creating an index on BIT(n) attribute in MySQL make sense?

I am working on a very specific thing and I need to use BIT(n) attributes and efficiently search through them. n is generally not a power of 2. I've seen some mentions on the internet that BIT ...
-2
votes
1answer
3k views

What are performance benefits when using number type instead of using char/varchar?

From various posts, I have summarized about using number type instead of char/varchar for PK: If you choose char/varchar type for PK and your values are short (just some alpha numberic codes) then it ...
4
votes
1answer
578 views

Why does using a Real data type in a mathematical equation return an incorrect result?

I was trying to figure out the source of what appeared to be a rounding error today, and discovered that one of the columns used in a mathematical equation was using the real data type, and this is ...
4
votes
1answer
111 views

Data type for a fuzzy date?

I want to store partial information related to a date. I might know the year and month but not the day. I might know the day and month but not the year. I might know the date lies in an open or closed ...
3
votes
1answer
1k views

Oracle integer to number conversion

According to the Oracle documentation, creating a table with a column of ANSI type INT, Oracle will convert it to NUMBER(38). According to the same document, NUMBER(38) is supposed to be a NUMBER ...
8
votes
3answers
518 views

What should I use? A string or 15 integer fields?

I am developing a student tracking program where I need to store 15 exam marks. I can store the marks as a string and split them up when I need to, for purposes such as performing arithmetical ...
5
votes
2answers
400 views

Determining the optimal Column Widths from a .csv File

I want to import a .CSV file into a MySQL Table. I would like to determine the optimal column widths to use based on the actual data contained in the CSV file. Are there any scripts or utilities to ...
2
votes
3answers
145 views

How to restrict sequence like ID type to C type like int64_t, uint64_t, int32_t?

In C99 I can be pretty clear about the size/domain of an integer type. When interfacing a SQL database like Oracle or Postgresql from a C program I want to create a table with integer types that ...
5
votes
2answers
3k views

Designing a user authenication (Roles & Rights) module

I am trying to model a User Authentication module for a MS SQL Server database that will be the back end to a Delphi UI Application. Basically, I want to have user accounts where the user belongs to ...
0
votes
1answer
44 views

Does a numeric field always use the same disk space?

When you have a numeric field in MySQL(MYISAM) (E.g. Integer) will it always use the same disk space, no matter what number is actually stored?
4
votes
1answer
198 views

How to set constraints on UDT in SQL Server 2005 - 2012

I'm creating my UDT: CREATE TYPE [dbo].[Code] FROM VARCHAR(20) NOT NULL As RULES and DEFAULTS are considered deprecated, what is the recommended way to set constraint on my type to make sure that ...
3
votes
2answers
4k views

changing float->numeric casts from assignment to implicit, dangerous?

In porting an application to PostgreSQL (9.1), one odd SQL incompatibility I've discovered concerns the round() function, specifically the version that takes a second argument indicating the rounding ...
4
votes
2answers
928 views

Change column data type across database

I have a bunch of tables with many columns of data type ntext. I wish to change all such columns in all tables of a particular database to nvarchar(max), because of planned deprecation (EDIT: also ...
6
votes
3answers
3k views

Should I add an arbitrary length limit to VARCHAR columns?

According to PostgreSQL's docs, there's no performance difference between VARCHAR, VARCHAR(n) and TEXT. Should I add an arbitrary length limit to a name or address column?
9
votes
2answers
3k views

SQL Server Decimal(9, 0) vs INT

One of our customers uses for some columns the datatype DECIMAL(18,0) in his SQL Server 2008R2 database. Because the columns grow quite slowly, he recently proposed to change the datatype to ...
7
votes
1answer
1k views

PostgreSQL data type text vs varchar without length

In PostgreSQL you can create a column with data type character varying (without length precision) or text like this: ALTER TABLE test ADD COLUMN c1 varchar; ALTER TABLE test ADD COLUMN c2 text; Is ...
6
votes
2answers
667 views

What are the pros/cons of splitting date and time into separate fields vs. using the datetime data type and storing the date in a single field?

My database is extremely large and growing at a rate of ~20m rows/day. I have timestamp data that is important but most of the reporting is based on date ranges and week over week or month over month ...
4
votes
2answers
6k views

A Script to insert dummy Data in all tables of Database

I wanted a Script that can loop through all tables and their columns in the database and insert dummy data based on column type and size, so that i can start using the database for testing, and ...
0
votes
1answer
388 views

What are commonly used database types? [closed]

There are a lot of database types. Can you list a list of the top classification of databases commonly found in schools and offices? Any help is appreciated. Hope to see compressed and summarized type ...
2
votes
1answer
541 views

Change in datatype?

I have a table on which rows are inserted on hourly basis. The row contains id, installation, product_id and hit_allowed. all of them were mediumint in the beginning. but few days back id reached it ...
10
votes
1answer
590 views

Why does 10^37 / 1 throw an arithmetic overflow error?

Continuing my recent trend of playing with large numbers, I recently boiled an error I was running into down to the following code: DECLARE @big_number DECIMAL(38,0) = '1' + REPLICATE(0, 37); PRINT ...
1
vote
3answers
123 views

Is there such thing as automatic ENUMs?

There are some tables that I manage which contain a string value (for example, a 4 word "Type" field). There are only a few DISTINCT strings, however the application may insert new strings that have ...
2
votes
1answer
100 views

Create a Function in sql server without specifying return_data_type

I am trying to create a Scalar-valued function in SQL server, without specifying the return_data_type i want to be able to return any datatype based on a parameter sent by the function caller e.g. ...
5
votes
2answers
3k views

Data type for storing an array of flags (a bitmap/bit array)

I need to store a bit array for each record of a table, supporting the following operations: Testing if a bit is set, and setting a bit (using SQL) Querying and setting the value using ADO 2.8 (not ...