SQL Server insert empty instance [duplicate] - sql

This question already has answers here:
How to insert a record with only default values?
(3 answers)
Closed 5 years ago.
SQL Server 2014
Given a table 'test' with the following fields:
id: int. Primary key. Autoincrement by 1.
creation_date: datetime. GETDATE() by default value.
My intention is to insert an empty statement, just to register the event of the insertion. I thought that as the id is an autoincrement and the creation_date has a value by default, a record could be inserted without specifying any value. I know that this can be done by adding a third field and specifying the value in the insertion, but my question is:
Can something like a plain INSERT INTO test be done?
Thanks

INSERT INTO test DEFAULT VALUES

Related

How can I limit what data is entered in SQL Server? [duplicate]

This question already has answers here:
SQL add a new column and its values only can be in several fixed options
(2 answers)
Closed 7 months ago.
For example: I have a column named Software, where I want only 2 entries either Hotel or Restro. Besides these two;Hotel and Restro, the column should not allow other data. I am trying to implement this database in Hotel Managemnet System through ASP.NET. So, is it possible in anyway in SQL Server?
You may use a check constraint in the create table definition:
CREATE TABLE yourTable (
Id INT IDENTITY PRIMARY KEY,
some_col VARCHAR(6) NOT NULL CHECK (some_col IN ('Hotel', 'Restro'))
-- rest of definition here
);

After I change the identity specification to "Yes", why does it change back to "No" in SQL Server? [duplicate]

This question already has answers here:
Can a sql server table have two identity columns?
(9 answers)
Closed 3 years ago.
I need to set 3 columns (idUser, idLab, idProfile) as identity, but when I change one of them all the others set identity as "No" and only the latest one sets to "Yes".
Already checked its data type and all are set to "int"
This is because you can have only one column as an identity column in your table.
Please refer Can a sql server table have two identity columns? also.
We really do not need multiple Identity column in a table as we can always get the value of the other two columns from the one Identity column. Here, in this case, idLab and idProfile values same as idUser.
So, if I set idUser to be an identity column, it should suffice for me.

How to change next default value for PostgreSQL sequence? [duplicate]

This question already has answers here:
How to reset Postgres' primary key sequence when it falls out of sync?
(33 answers)
Closed 3 years ago.
I have a table where the ID sequence goes like 01,02 and so on (I have a few pre-inserted values). When I try to insert a new row there (not specifying the ID explicitly, but rather values for other columns) it tells me that the default value is "1" which is the same as "01" and can't be inserted. How to fix it, thank you!
You can use START WITH argument while creating the sequence.
Example:
CREATE SEQUENCE sequenceName
START WITH 1
INCREMENT BY 1 ;
For more documentation go through the link

How to check if a value in a column is GUID in sql server? [duplicate]

This question already has answers here:
How to check if a string is a uniqueidentifier?
(15 answers)
Closed 8 years ago.
I have a column which is of type nvarchar, once the row is processed it updates it with a unique identifier. I need to insert the values other than GUID and NULL into a different table. Is there any built in function to determine whether the value in the column is unique identifier?
I found a way to check it:
SELECT 1 WHERE #StringToCompare LIKE REPLACE('00000000-0000-0000-0000-000000000000', '0', '[0-9a-fA-F]');
or you could see this page for more solutions:
How to check if a string is a uniqueidentifier?
I think There is no such functions, which will determine weather Field is unique / repetitive
only Primary Key constraints / Primary Key to the table will (decides / checks) UID or Not-a- UID .

Getting Identity Column Value [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to get the primary key of the last row inserted into the table
In SQL Server 2008, I have a stored proc that inserts in a table which includes identity column for ID. I need to return the ID of record to my application so that I can use it for related tables.
How can I get generated ID by SQL?
Use select Scope_Identity() to get the ID
A separate SQL statement
SELECT SCOPE_IDENTITY()
Or the OUTPUT clause
INSERT MyTable (...=
OUTPUT INSERTED.KeyCol
VALUES (...) --Or SELECT ... FROM Another table)
There are multiple options that are a bit different:
SCOPE_IDENTITY() - that's what I would use
IDENT_CURRENT( 'table_name' )
##IDENTITY