I have a foreign key (IdForign), and always use it in where clause.
I have three fields:
Id
Name
IdForign
How can i create the index for the Name field?
(IdForign, Name) or just one for IdForign and other for Name?
Thanks!!
If I undertand correctly your question, you need to create an Index only for IdForign, because it's the one you use in the where
UPDATE
As per your comment, if you are using both fields I suggest you to use an index with Name and IdForign
Read this. It should give you some tips on indexing with Sql Server
The basic systax, which it seems is all you are asking for is:
CREATE INDEX yourIndexName ON yourTableName (yourFieldName);
This is also assuming you mean Microsoft SQL Server. See here for the MSDN documentation.
I hope this helps.
Related
Currently I have a table in SQL Server 2008 R2 as below
What I'm trying to do is to transform my table into below :
The concept of how it work is value will keep the first Start and End Value, I don't know how to explain this with the word, but if I draw this into the table, it would be like this :
Honestly, I already found a solution for this issue but it only can do with 2 columns, link: SQL: Merge Date Ranges
I am always failing while trying to do this with my table.
Thanks! Appreciate any answer or suggestion!
I think this is what you are trying to achieve.
Select Sites, Min(Range_Start) as New_Start, Max(Range_End) as New_End
from Table_Name
Group by Sites
I believe there is a new feature where you can define columns as HIDDEN so that a SELECT * returns all except hidden columns.
Is this possible? If yes, how would you achieve it with SQL Server 2016 or SQL Azure?
Adding info from the comments into the answer..
We cant specify a column as hidden and do a select * which returns all columns except hidden like Temporal tables.Moreover this feature is applicable only for validfrom,valid to columns ,though it is nice to have such a feature.As Satya mentioned you can use views to achieve more or less the same.
I have created a table that has a column with the name started of type datetime. I was very surprised to see this turn blue when I copied my select statement into management studio. When looking at the list of reserved words for SQL in the Microsoft documentation (see here), I cannot find the word started.
What is it? What does it do?
A very old SSMS problem.
I'm afraid M$ doesn't care about some tokens treated as keywords.
See this.
I don't think so. There is no keyword exist with the name started.
I was able to create table
SQLFiddle Demo
Is there a nice way before I alter a table (e.g. remove a column), to see if that this will break any stored procedures?
I am trying to do this in MS SQL Server
Use the query here to search all stored procedures for the table and column name. You will probably still want to look at the code for each one you find to verify that it will or won't break.
you can use the following query to search for the table name in any stored procedures:
SELECT name
FROM sys.procedures
WHERE Object_definition(object_id) LIKE '%Your_Table_Name%'
I suggest you:
Make sure you have a separate environment (DEV)
Use the sample code from here to create a proc that confirms all objects in the database can be recompiled
How to Check all stored procedure is ok in sql server?
Use it - I can guarantee you will already have failing objects before you remove your column
Remove your column and use it again to see if more things broke
The more mature approach to this is to put your database into a database project and build that. But you can't do this until your database is valid.
I am connected with postgresql-simple and need to get a list of tables in the current db.
psql has \d
haskelldb has 'tables', which yields the dbTables attribute in the connection object (i think that's what it was called)
HDBC has getTables
what is the way to do this in postgresql-simple?
thanks,
m.
as already answered in a comment above (due to lack of privileges): don't use postgresql-simple at all, but plain SQL on the internal postgresql tables:
select schemaname, tablename from pg_tables;
sorry for the noise.