sql-server-2012

Determine whether SP Parameter has a Default Value in T-SQL

久未见 提交于 2019-12-29 08:33:14
问题 Is there any way to determine from within SQL Server (I'm on 2012 FYI) if a SP's parameters have default values? There are other threads on this, however the suggestions don't seem to get me this information accurately. Here are a couple of things I've tried; select * from sys.objects so join sys.parameters sp on so.object_id = sp.object_id where so.type='P' and so.name = 'someSp' The above query returns a number of columns that sound like I'm barking up the right tree (has_default_value,

Select non-empty columns using SQL Server

筅森魡賤 提交于 2019-12-29 08:24:09
问题 I am using SQL Server 2012. i have a table with 90 columns. I am trying to select only columns that contains data. After searching i used the following procedure: 1- Getting all columns count using one select query 2- Pivoting Result Table into a Temp table 3- Creating Select query 4- Executing this query Here is the query i used: DECLARE @strTablename varchar(100) = 'dbo.MyTable' DECLARE @strQuery varchar(max) = '' DECLARE @strSecondQuery varchar(max) = 'SELECT ' DECLARE @strUnPivot as

Recursive Query for Bill Of Materials

╄→гoц情女王★ 提交于 2019-12-29 07:14:32
问题 I've just started teaching myself SQL recently and have been able to piece together almost everything I need from various tutorials, but this one has me banging my head against the wall. We have a table that contains all the bill of material information for our products. I only need 4 of the columns from it - PPN_I, CPN_I, QUANTITY_I, BOMNAME_I - which are Item Number, Raw Material number, quantity, and the BOMName, respectively. Many of the BOMs contain subassemblies. I need a result set

Create Database in SQL Server 2012, Script and Use in 2008?

社会主义新天地 提交于 2019-12-29 05:21:09
问题 If I create a database using 2012 and work and add that info to it, if I were to script the database after, would I be able to run the script in 2008 and have everything work A.O.K? 回答1: A script? Yes. Well, let me rephrase: it depends. As long as your objects don't use any 2012-specific features, you will be able to script out the schema using Management Studio or a variety of 3rd party tools (I blogged about some options here). Many of the tools also offer options (or companion tools) to

Count Number of Consecutive Occurrence of values in Table

拈花ヽ惹草 提交于 2019-12-28 12:01:15
问题 I have below table create table #t (Id int, Name char) insert into #t values (1, 'A'), (2, 'A'), (3, 'B'), (4, 'B'), (5, 'B'), (6, 'B'), (7, 'C'), (8, 'B'), (9, 'B') I want to count consecutive values in name column +------+------------+ | Name | Repetition | +------+------------+ | A | 2 | | B | 4 | | C | 1 | | B | 2 | +------+------------+ The best thing I tried is: select Name , COUNT(*) over (partition by Name order by Id) AS Repetition from #t order by Id but it doesn't give me expected

Using MVC 4 SimpleMembership with an existing database-first EF model

这一生的挚爱 提交于 2019-12-28 10:07:25
问题 I am trying to use SimpleMembership in my MVC 4 for the first time and I already have an existing database and EF5 model created based on it! I searched a lot but I cant find how I could use it in my case and also to have everything under my own model. It would be great if somebody can give me an idea how to do this. Thanks 回答1: Purely as a point of reference, it might be a good idea to create a new Internet Application template of an ASP.NET MVC 4 Web Application project (i.e. via File > New

Stored procedure EXEC vs sp_executesql difference?

社会主义新天地 提交于 2019-12-28 06:17:06
问题 I've written two stored procedure one with sp_executesql and other doesn't have sp_executesql both are executing properly same results, I didn't get what is the difference here between EXEC (@SQL) vs EXEC sp_executesql @SQL, N'@eStatus varchar(12)', @eStatus = @Status and How EXEC(@SQL) is prone to SQL injection and sp_executesql @SQL...... isn't? Below Stored Procedure without sp_executesql ALTER proc USP_GetEmpByStatus ( @Status varchar(12) ) AS BEGIN DECLARE @TableName AS sysname =

There are no Primary or Candidate Keys in the referenced table

痞子三分冷 提交于 2019-12-28 04:22:08
问题 Error: There are no Primary or Candidate Keys in the referenced table 'dbo.Customers' that match the referencing column list in the foreign key 'FK_Reservation_Customers_FrstNme FOREIGN KEY' DROP TABLE dbo.Customers; DROP TABLE dbo.Staff; DROP TABLE dbo.Rooms; DROP TABLE dbo.Reservation; GO CREATE TABLE "Customers"( CustomerID int IDENTITY (1,1) NOT NULL, FirstName nvarchar(20) NULL, LastName nvarchar(20) NULL, StreetNo int NULL, City nvarchar(20) NULL, PostCode nvarchar(20) NULL, Email

Why the SQL Server ignore the empty space at the end automatically?

爷,独闯天下 提交于 2019-12-28 04:18:19
问题 I wrote a query SELECT * FROM Users WHERE UserName = 'admin ' by mistaken typing. But I found that the result is as the same as SELECT * FROM Users WHERE UserName = 'admin' It seems that the empty space at the end is ignored by SQL Server automatically. Can anybody tell me why? FYI, the column UserName is of type nvarchar(MAX) . 回答1: SQL Server is following the ANSI/ISO standard for string comparison. The article How SQL Server Compares Strings with Trailing Spaces explains this in detail.

Restore a SQL Server 2000 backup on SQL Server 2012

帅比萌擦擦* 提交于 2019-12-28 04:00:49
问题 I have got following error message while restoring a backup from SQL Server 2000 to the latest version. I do not know the old version, now I am using SQL Server 2012 (11.0.3128.0). The error message is: Msg 3169, Level 16, State 1, Server FF101, Line 1 The database was backed up on a server running version 8.00.0760. That version is incompatible with this server, which is running version 11.00.3128. Either restore the database on a server that supports the backup, or use a backup that is