CROSS JOIN vs INNER JOIN in SQL

Here is the best example of Cross Join and Inner Join. Consider the following tables TABLE : Teacher x————————x | TchrId | TeacherName | x———-|————-x | T1 | Mary | | T2 | Jim | x————————x TABLE : Student x————————————–x | StudId | TchrId | StudentName | x———-|————-|————-x | S1 | T1 | Vineeth | … Read more

How to generate a range of numbers between two numbers?

Select non-persisted values with the VALUES keyword. Then use JOINs to generate lots and lots of combinations (can be extended to create hundreds of thousands of rows and beyond). Short and fast version (not that easy to read): WITH x AS (SELECT n FROM (VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) v(n)) SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM … Read more

Format of the initialization string does not conform to specification starting at index 0

Check your connection string. If you need help with it check Connection Strings, which has a list of commonly used ones. Commonly used Connection Strings: SQL Server 2012 Standard Security Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword; Trusted Connection Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; Connection to a SQL Server instance The server/instance name syntax used in the server option is the same for all … Read more

How to find server name of SQL Server Management Studio

Open up SQL Server Configuration Manager (search for it in the Start menu). Click on SQL Server Services. The instance name of SQL Server is in parenthesis inline with SQL Server service. If it says MSSQLSERVER, then it’s the default instance. To connect to it in Management Studio, just type . (dot) OR (local) and … Read more

Select SQL Server database size

Try this one – Query: SELECT database_name = DB_NAME(database_id) , log_size_mb = CAST(SUM(CASE WHEN type_desc=”LOG” THEN size END) * 8. / 1024 AS DECIMAL(8,2)) , row_size_mb = CAST(SUM(CASE WHEN type_desc=”ROWS” THEN size END) * 8. / 1024 AS DECIMAL(8,2)) , total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2)) FROM sys.master_files WITH(NOWAIT) WHERE database_id = … Read more

Copy data into another table

If both tables are truly the same schema: INSERT INTO newTable SELECT * FROM oldTable Otherwise, you’ll have to specify the column names (the column list for newTable is optional if you are specifying a value for all columns and selecting columns in the same order as newTable‘s schema): INSERT INTO newTable (col1, col2, col3) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)