sqldatatypes

Difference between Varchar(max) and nvarchar(max) [duplicate]

两盒软妹~` 提交于 2020-01-02 08:13:20
问题 This question already has answers here : What is the difference between varchar and nvarchar? (18 answers) Closed 4 years ago . I came across a question while buidling schema for my application. When to use varchar(max) and nvarchar(max) . I mean the exact use cases where it should be applied. I have surfed in net too but I was able to get the exact answer. Could anyone suggest some exact usecase. 回答1: This is for Microsoft SQL Server : NVARCHAR is Unicode - 2 bytes per character, therefore

Store time interval in PostgreSQL from Rails

依然范特西╮ 提交于 2020-01-02 07:40:11
问题 I need to store time inverval in PosgreSQL. Data will be put from Ruby on Rails. Say, PizzaHut accepts orders from 9:00 to 18:00. I've created following migration: class AddOrderTimeAndDeliveryTimeToMerchants < ActiveRecord::Migration def self.up add_column :merchants, :order_time, :interval end I've read the documentation, and have following code now: Merchant.create( :delivery_time => "9:00 18:00" ) When i execute it, i get following error message: PGError: ERROR: invalid input syntax for

Store time interval in PostgreSQL from Rails

断了今生、忘了曾经 提交于 2020-01-02 07:39:09
问题 I need to store time inverval in PosgreSQL. Data will be put from Ruby on Rails. Say, PizzaHut accepts orders from 9:00 to 18:00. I've created following migration: class AddOrderTimeAndDeliveryTimeToMerchants < ActiveRecord::Migration def self.up add_column :merchants, :order_time, :interval end I've read the documentation, and have following code now: Merchant.create( :delivery_time => "9:00 18:00" ) When i execute it, i get following error message: PGError: ERROR: invalid input syntax for

Crypto Currency MySQL Datatypes ?

拥有回忆 提交于 2020-01-01 08:22:24
问题 The infamous question about datatypes when storing money values in an SQL database. However in these trying times, we now have currencies that have worth up to 18 decimal places (thank you ETH). This now reraises the classic argument. IDEAS Option 1 BIGINT Use a big integer to save the real value, then store how many decimal places the currency has (simply dividing A by 10^B in translation)? Option 2 Decimal(60,30) Store the datatype in a large decimal, which inevitibly will cost a large

Is there any difference between integer and bit(n) data types for a bitmask?

老子叫甜甜 提交于 2020-01-01 07:50:07
问题 I am working with a table in a PostgreSQL database that has several boolean columns that determine some state (e.g. published , visible , etc.). I want to make a single status column that will store all these values as well as possible new ones in a form of a bitmask. Is there any difference between integer and bit(n) in this case? This is going to be a rather big table, because it stores objects that users create via a web-interface. So I think I will have to use (partial) indexes for this

How can I map TIMESTAMP WITH TIME ZONE to a Java data type using Hibernate 3.3.2GA?

喜夏-厌秋 提交于 2020-01-01 06:29:31
问题 How can I map Oracle column types TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE to a Java data type using Hibernate 3.3.2GA? Can I map each of these to a Date or Calendar data type? 回答1: Use joda-time. It has an extension for hibernate @Columns(columns={@Column(name="startTime"),@Column(name="startTimezone")}) @Type(type="org.joda.time.contrib.hibernate.PersistentDateTimeTZ") private DateTime startDateTime; But first make sure you really need to store the time-zone. A better

Want to restrict the value of a MySQL field to specific range (Decimal values)

做~自己de王妃 提交于 2020-01-01 03:33:06
问题 I want to restrict the value of a field in a row of a table to a specific range. Is it possible to restrict my relationship_level field to [0.00 to 1.00] ? At the moment I am using DECIMAL(2,2), it wouldn't allow DECIMAL(1,2) as M must be >= D. I assume a data type of DECIMAL(2,2) will actually allow values from 00.00 up to 99.99? CREATE TABLE relationships ( from_user_id MEDIUMINT UNSIGNED NOT NULL, to_user_id MEDIUMINT UNSIGNED NOT NULL, relationship_level DECIMAL(2,2) UNSIGNED NOT NULL,

SQL Server Management Studio make default date 5 days from now

大兔子大兔子 提交于 2019-12-31 05:10:22
问题 I am working on a database and I need to make the default value for a date column to be 5 days from the current date. Would using getdate() + 5 work? I'm using the GUI at the moment. Would a query like this work? ALTER TABLE Order ADD CONSTRAINT DF_Order DEFAULT GETDATE()+5 FOR DateofOrder Thanks. 回答1: Yout can tryout DateAdd function for adding days to date Example DATEADD(day,1,@datetimevar/column) try like this create table t( i int, d datetime default (dateadd(day,5,getdate())) ) 来源:

How to retrieve VARBINARY values from SQL Server 2008 using VB.Net

爷,独闯天下 提交于 2019-12-31 05:08:06
问题 I'm trying to populate a listview with varBinary(max) values. Well, I actually need to write each varBinary into a csv file and the table consists of 100 000 odd rows. I just don't know how to retrieve the datatype! Sub getInformation() Try If Not String.IsNullOrWhiteSpace(connString) Then Using cn As SqlConnection = New SqlConnection(connString) cn.Open() Using cmd As SqlCommand = New SqlCommand() cmd.Connection = cn Dim qry As String qry = String.Format("SELECT [varBinaryField] FROM [dbX].

What's the purpose of varchar(0)

柔情痞子 提交于 2019-12-29 07:35:09
问题 I recently encountered a problem caused by a typo in the database creation script, whereby a column in the database was created as varchar(0) instead of varchar(20) . I expected that I would have gotten an error for 0-length string field, but I didn't. What is the purpose of varchar(0) or char(0) as I wouldn't be able to store any data in this column anyway. 回答1: It's not allowed per the SQL-92 standard, but permitted in MySQL. From the MySQL manual: MySQL permits you to create a column of