add new column if not exists in sqlite [duplicate] - sql

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.

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
);

How to make a column update automatically in another table when a record is inserted into the table [duplicate]

This question already has answers here:
mysql - Automatically update occurrences in another table
(2 answers)
Closed 4 years ago.
When a record is inserted into a table, QuantityInHand in the Items table should be updated automatically. The two tables are Transactions.OrderDetails and Items.ItemDetails.
I've tried something like this:
Create Trigger items.trgItemDetails
on items.ItemDetails
After update
As
Begin
Update items.ItemDetails
Set Items.itemDetails.QuantityInHand = ItemID
From Inserted
where inserted.ItemID = Items.ItemDetails
End
Please, how can I solve this problem?
Thanks.
you can achieve this using Triggers.
check the link below
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql

How can I create a SQL table from another table without copying any values from the old table [duplicate]

This question already has answers here:
How can I create a copy of an Oracle table without copying the data?
(17 answers)
Closed 9 years ago.
How to create table with existing table structure without iterate row by row like this in Oracle? Thanks in Advance.
CREATE TABLE new_table
AS (SELECT *
FROM old_table WHERE 1=2);
If you are worried about iterating through the table:
CREATE TABLE new_table
AS (SELECT *
FROM (select * old_table where rownum = 1) t
WHERE 1=2
);
I have already read about this.. Hope it gives a Detailed explanation to you..
What we ended up doing in this clients case was to replace the “WHERE 1=2” with a clause that equated the primary key of the table with an impossible value for that key, in this case the ID was being passed in as a GUID (a hexadecimal value) so we use a “WHERE KEY=HEX(00)” and got a low cost unique index lookup instead of a costly full table scan.
http://www.dba-oracle.com/oracle_tips_ault_where_1_equals_2_parallel_.htm
Thanks to Burleson Consulting
I'm not sure on the exact Oracle syntax but in virtually any SQL if you open up the other table using a GUI tool there are options both to generate a create script statement for the table and to backup the table without data.
Either of those will do what you need.

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 .

CREATE TABLE IF NOT EXISTS equivalent in SQL Server [duplicate]

This question already has answers here:
Check if table exists in SQL Server
(29 answers)
Closed 3 years ago.
The community reviewed whether to reopen this question 6 months ago and left it closed:
Original close reason(s) were not resolved
CREATE TABLE IF NOT EXISTS works on mysql but fails with SQL Server 2008 R2.
What is the equivalent syntax?
if not exists (select * from sysobjects where name='cars' and xtype='U')
create table cars (
Name varchar(64) not null
)
go
The above will create a table called cars if the table does not already exist.