good day.. just want to ask, is it possible to alter a column table and make the default value to empty string.. i tried using this query, Alter Table Employee Alter Column sJobTitle Varchar(…
Tag: sql
How to store historical records in a history table in SQL Server
I have 2 tables, Table-A and Table-A-History. Table-A contains current data rows. Table-A-History contains historical data I would like to have the most current row of my data in Table-A, and Table-A-History containing historical rows. I can think of 2 ways to accomplish this: whenever a new data row is avail…
Problems with Postgresql CASE syntax
Here is my SQL query: When I execute the above query, I get this error: ERROR: CASE types record and integer cannot be matched From the error message I understand that PostgreSQL take the second select, respectively elapsed_time_from_first_login as a row, even if it will always be a single value (because of t…
SQL Column definition : default value and not null redundant?
I’ve seen many times the following syntax which defines a column in a create/alter DDL statement: The question is: since a default value is specified, is it necessary to also specify that the column should not accept NULLs ? In other words, doesn’t DEFAULT render NOT NULL redundant ? Answer DEFAUL…
Delete many records from table A and B with one FK to table B
I have 2 tables: A and B A contains the following columns: B contains the following: B has a reference to A from A_id column (FK) The question: I want to delete all records from table A that their checkpoint_id is less than X: But I can’t do it since “The primary key value cannot be deleted becaus…
sqlalchemy simple example of `sum`, `average`, `min`, `max`
For sqlalchemy, Who can gently give simple examples of SQL functions like sum, average, min, max, for a column (score in the following as an example). As for this mapper: Answer See SQL Expression Language Tutorial for the usage. The code below shows the usage:
Combine multiple SELECT statements
I’ve used Excel to generate numerous SELECT statements from a list of the schema names from a database with a large number of identical schemas: select result from foo.table limit 1; select result …
Inner Joining three tables
I have three tables I wish to inner join by a common column between them. Say my tables are; TableA TableB TableC I wish to join A-B, but then also B-C all by this common field I will call common. …
GROUP BY and COUNT in PostgreSQL
The query: Returns n records in Postgresql: I just want to retrieve the number of records returned: 6. I used a subquery to achieve what I want, but this doesn’t seem optimum: How would I get the number of records in this context right in PostgreSQL? Answer I think you just need COUNT(DISTINCT post_id) …
Insert multiple rows into single column
I’m new to SQL, (using SQL 2008 R2) and I am having trouble inserting multiple rows into a single column. I have a table named Data and this is what I am trying That code was taken from this question, but it, like many other examples I have found on the web uses 2 columns, I just want to use