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
);
Related
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.
This question already has answers here:
Check if a column exists in SQLite
(17 answers)
Closed 5 years ago.
Hi Im using this query in sqlite
tx.executeSql('CREATE TABLE IF NOT EXISTS STU_REMAINDER( REG_NO VARCHAR(15), REM_ID INTEGER, REM_DATETIME DATETIME, DETAILS VARCHAR(500),STATUS INTEGER )');
I want to add column SCH_ID in this table, if not exist in this column. Thank you.
I prefer using a GUI Firefox addon Sqlite Manager to work with Sqlite database. You can download it from below url
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
You can view queries in it too when you add or alter table.
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
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 .
This question already has answers here:
How to update data in one table from corresponding data in another table in SQL Server 2005
(8 answers)
Closed 9 years ago.
I have two databases (test1 and test2) on the same server, which have the same tables (Employee) with the same scheme. Employee holds around 1.500 rows.
Now I want to copy the value of column EmpDepID for each PK.
How can I achieve this?
UPDATE [test1].[dbo].[Employee]
SET [EmpDepID] = test2.[EmpDepID]
FROM [test2].[dbo].[Employee] test2
WHERE test2.[PK] = [test1].[dbo].[Employee].[PK]
as stated by #AdiInbar, the obvious intention of this question was something completely different.
original answer:
INSERT INTO [database1].[dbo].[table1]
(
/* TODO: define columns */
)
SELECT * /* or specify the columns */
FROM [database2].[dbo].[table2]