date and time not being added to table with correct default and datatype - sql

I am using AnySQL Maestro 13.2.0.15 which is SQL-server based. I need the date and time to automatically be put in the column "added" of my table called "accntgs" with out me having to select the current date and time. I have added the field with the datetime data type and set the default to getdate(), but then when I enter a new record and post it, the added field is still null. I have also tried to use the timestamp data type, and when I post a new record with that, the added field says (bytes) and does not have the date or the time. How do I fix this and get the date and time the record is posted to show up.
I have also tried this:
ALTER TABLE accntgs ADD CONSTRAINT
DF_accntgs_added DEFAULT GETDATE() FOR added
and it didnt add the the date when the new record was posted either

Related

Is it possible to store a variable (int) in SQL to then take effect once a certain date has been reached?

Is it possible to store a variable in a SQL table which will only take effect once a certain date is reached? The variable is the amount of days that would be added to a date to create a "TargetDate", this variable can be changed by user input but must have an "EffectiveDate" ?
You can certainly create a configuration table that you store config data in. In your case, one of the items would be 'EFCTV_BUFFER' as the value in the key column, and (for an example) '5' as the number of days in the value column. Then you can reference that key value to select the buffer days value, and add that to whatever date you want.
This allows you to modify it at any time as requested.
You would reference this table in an insert/update trigger on your table where you store your dates. I would suggest having two dates so that the calculation is only done once, unless you need the calculation to be dynamic based upon the current 'EFCTV_BUFFER' configuration value.

In Mongo DB , How to get the inital date of data insertion

I entered many data in MongoDB on different dates,
for example
from January, each day I entered data, how to know which date I started data insertion process
I think that there is no way to find that out, a workaround for that is you can alter your table and add a timestamp column, with default value now().
That let you see when future inserts are created.

I want a default on a column(smalldatetime data type) where the time value is current time + 6hrs and updates continuously

I want a default on a column(smalldatetime data type) where the time value in each row is current time + 6hrs.
I tried using the Getdate() function but it doesnt update. Instead it just provides a stamp of when the rows were created. You can see that I tried the script in this post. I thought it had worked but when I checked the table the next day the time had never changed.I would like to set the Default value for a column to Current Time + 6hrs
Thanks in advance for any help offered.
Add the following field to your view:
DATEADD(hour, 6, GETDATE()) AS Minimum_Departure_Time
Since you want it to change when you look at it, there is no reason to put it in the table. Just put it in your view since the view is dynamically created everytime it is run.

How to add a record to a table

I would like to create an control on embedded on a continuous form of which its activation event creates a new record on the form and inserts today's date in the date field. I was thinking to use an SQL query to create the record but still am having difficulty.
Maybe you should try this...
In the table being inserted into, add a field called "date_entered" and have its default
value set to "Now()". This will give you a timestamp (knowledge of when the record was entered).
Doing it this way is the easiest way, and then you don't have to write any extra code.

SQL Default Constraint

I have a table with 2 columns dateRecieved and dateDue. I know how to make the dateNow column show today's date by default by using:
DEFAULT GETDATE()
The user can then modify the dateRecieved column to whatever date they want.
After the user modifies the dateRecieved column; how do I set up the dateDue column so that it, by default, shows a date x days away from dateRecieved?
I looked at this answer but I need to refer to another column.
Need to add constraint: date plus 10 days
Is there a way that dateRecieved can modify its value automatically when dateRecieved changes?
The user should be able to override the default values in both these columns.
I'm using the W3 schools sql tutorial but it didn't have and answer I couldn't find one on stackoverflow either
http://www.w3schools.com/sql/sql_default.asp
use current date as default value for a column
Thanks
So when you say the "user modifies" you are talking about an UPDATE.
DEFAULT values are relevant to INSERT statements only.
It is true you can accomplish whatever automagical UPDATE change you want via triggers but as a beginner, I would squarely advise you away from triggers. They are rarely implemented correctly and make understanding when things go wrong more difficult.
What you want to do is INSERT your row(s) (allowing any DEFAULT values to "happen") and then UPDATE your row(s) with the values you intended.
It sounds like what you're looking for is a trigger that waits until the update is finished, then the dateDue automatically updates.
This answer may point you in the right direction:
How to: Create trigger for auto update modified date with SQL Server 2008