Skip to content

How do I get constraints on a SQL Server table column

I have a column called MealType (VARCHAR) in my table with a CHECK constraint for {“Veg”, “NonVeg”, “Vegan”} That’ll take care of insertion. I’d like to display these options for selection, but I couldn’t figure out the SQL query to find out the constraint…

Unable to open BCP host data-file

Below is an example of the BCP Statement. I’m not accustomed to using BCP so your help and candor is greatly appreciated I am using it with a format file as well. If I execute from CMD prompt it works fine but from SQL I get the error. The BCP statement is all on one line and the SQL Server

Insert distinct values from one table into another table

So for each distinct value in a column of one table I want to insert that unique value into a row of another table. Any ideas as to how to go about this? Answer Whenever you think about doing something in a loop, step back, and think again. SQL is optimized to work with sets. You can do this using

T-SQL – compare strings char by char

I need to compare two strings character by character using T-SQL. Let’s assume i have twor strings like these: 123456789 212456789 Every time the character DO NOT match, I would like to increase …

how to convert date to a format `mm/dd/yyyy`

I’m having a sql table with date column named CREATED_TS which holds the dates in different format eg. as shown below Now I want to convert these to format mmddyyyy before as i am comparing the dates in WHERE clause of my SELECT query. I tried using but got the result as, I need the result as eg. 02/20/…

Temp sequence in postgres view

I have a table that I order a certain way often. That ordering is the basis of a derived column we can call rank. If I query the entire table, I can have the database calculate that rank for me: This yields useful results like: With that result set I can determine the rank of any foo. However this requires